/src/llvm-project/clang/lib/Basic/SanitizerSpecialCaseList.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- SanitizerSpecialCaseList.cpp - SCL for sanitizers ----------------===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // An extension of SpecialCaseList to allowing querying sections by |
10 | | // SanitizerMask. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | #include "clang/Basic/SanitizerSpecialCaseList.h" |
14 | | |
15 | | using namespace clang; |
16 | | |
17 | | std::unique_ptr<SanitizerSpecialCaseList> |
18 | | SanitizerSpecialCaseList::create(const std::vector<std::string> &Paths, |
19 | | llvm::vfs::FileSystem &VFS, |
20 | 46 | std::string &Error) { |
21 | 46 | std::unique_ptr<clang::SanitizerSpecialCaseList> SSCL( |
22 | 46 | new SanitizerSpecialCaseList()); |
23 | 46 | if (SSCL->createInternal(Paths, VFS, Error)) { |
24 | 46 | SSCL->createSanitizerSections(); |
25 | 46 | return SSCL; |
26 | 46 | } |
27 | 0 | return nullptr; |
28 | 46 | } |
29 | | |
30 | | std::unique_ptr<SanitizerSpecialCaseList> |
31 | | SanitizerSpecialCaseList::createOrDie(const std::vector<std::string> &Paths, |
32 | 46 | llvm::vfs::FileSystem &VFS) { |
33 | 46 | std::string Error; |
34 | 46 | if (auto SSCL = create(Paths, VFS, Error)) |
35 | 46 | return SSCL; |
36 | 0 | llvm::report_fatal_error(StringRef(Error)); |
37 | 0 | } |
38 | | |
39 | 46 | void SanitizerSpecialCaseList::createSanitizerSections() { |
40 | 46 | for (auto &It : Sections) { |
41 | 0 | auto &S = It.second; |
42 | 0 | SanitizerMask Mask; |
43 | |
|
44 | 0 | #define SANITIZER(NAME, ID) \ |
45 | 0 | if (S.SectionMatcher->match(NAME)) \ |
46 | 0 | Mask |= SanitizerKind::ID; |
47 | 0 | #define SANITIZER_GROUP(NAME, ID, ALIAS) SANITIZER(NAME, ID) |
48 | |
|
49 | 0 | #include "clang/Basic/Sanitizers.def" |
50 | 0 | #undef SANITIZER |
51 | 0 | #undef SANITIZER_GROUP |
52 | |
|
53 | 0 | SanitizerSections.emplace_back(Mask, S.Entries); |
54 | 0 | } |
55 | 46 | } |
56 | | |
57 | | bool SanitizerSpecialCaseList::inSection(SanitizerMask Mask, StringRef Prefix, |
58 | | StringRef Query, |
59 | 0 | StringRef Category) const { |
60 | 0 | for (auto &S : SanitizerSections) |
61 | 0 | if ((S.Mask & Mask) && |
62 | 0 | SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category)) |
63 | 0 | return true; |
64 | | |
65 | 0 | return false; |
66 | 0 | } |