Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 1 | //===--- SanitizerSpecialCaseList.cpp - SCL for sanitizers ----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // An extension of SpecialCaseList to allowing querying sections by |
| 11 | // SanitizerMask. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | #include "clang/Basic/SanitizerSpecialCaseList.h" |
| 15 | |
| 16 | using namespace clang; |
| 17 | |
| 18 | std::unique_ptr<SanitizerSpecialCaseList> |
| 19 | SanitizerSpecialCaseList::create(const std::vector<std::string> &Paths, |
| 20 | std::string &Error) { |
| 21 | std::unique_ptr<clang::SanitizerSpecialCaseList> SSCL( |
| 22 | new SanitizerSpecialCaseList()); |
| 23 | if (SSCL->createInternal(Paths, Error)) { |
| 24 | SSCL->createSanitizerSections(); |
| 25 | return SSCL; |
| 26 | } |
| 27 | return nullptr; |
| 28 | } |
| 29 | |
| 30 | std::unique_ptr<SanitizerSpecialCaseList> |
| 31 | SanitizerSpecialCaseList::createOrDie(const std::vector<std::string> &Paths) { |
| 32 | std::string Error; |
| 33 | if (auto SSCL = create(Paths, Error)) |
| 34 | return SSCL; |
| 35 | llvm::report_fatal_error(Error); |
| 36 | } |
| 37 | |
| 38 | void SanitizerSpecialCaseList::createSanitizerSections() { |
| 39 | for (auto &S : Sections) { |
| 40 | SanitizerMask Mask = 0; |
| 41 | |
| 42 | #define SANITIZER(NAME, ID) \ |
| 43 | if (S.SectionMatcher->match(NAME)) \ |
| 44 | Mask |= SanitizerKind::ID; |
| 45 | #define SANITIZER_GROUP(NAME, ID, ALIAS) SANITIZER(NAME, ID) |
| 46 | |
| 47 | #include "clang/Basic/Sanitizers.def" |
| 48 | #undef SANITIZER |
| 49 | #undef SANITIZER_GROUP |
| 50 | |
| 51 | SanitizerSections.emplace_back(Mask, S.Entries); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | bool SanitizerSpecialCaseList::inSection(SanitizerMask Mask, StringRef Prefix, |
| 56 | StringRef Query, |
| 57 | StringRef Category) const { |
| 58 | for (auto &S : SanitizerSections) |
| 59 | if ((S.Mask & Mask) && |
Mitch Phillips | 512fa40 | 2017-11-07 21:16:37 +0000 | [diff] [blame] | 60 | SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category)) |
Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 61 | return true; |
| 62 | |
| 63 | return false; |
| 64 | } |