Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 1 | //===--- SanitizerSpecialCaseList.cpp - SCL for sanitizers ----------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 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 | std::string &Error) { |
| 20 | std::unique_ptr<clang::SanitizerSpecialCaseList> SSCL( |
| 21 | new SanitizerSpecialCaseList()); |
| 22 | if (SSCL->createInternal(Paths, Error)) { |
| 23 | SSCL->createSanitizerSections(); |
| 24 | return SSCL; |
| 25 | } |
| 26 | return nullptr; |
| 27 | } |
| 28 | |
| 29 | std::unique_ptr<SanitizerSpecialCaseList> |
| 30 | SanitizerSpecialCaseList::createOrDie(const std::vector<std::string> &Paths) { |
| 31 | std::string Error; |
| 32 | if (auto SSCL = create(Paths, Error)) |
| 33 | return SSCL; |
| 34 | llvm::report_fatal_error(Error); |
| 35 | } |
| 36 | |
| 37 | void SanitizerSpecialCaseList::createSanitizerSections() { |
| 38 | for (auto &S : Sections) { |
Pierre Gousseau | ae5303d | 2019-03-01 10:05:15 +0000 | [diff] [blame^] | 39 | SanitizerMask Mask; |
Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 40 | |
| 41 | #define SANITIZER(NAME, ID) \ |
| 42 | if (S.SectionMatcher->match(NAME)) \ |
| 43 | Mask |= SanitizerKind::ID; |
| 44 | #define SANITIZER_GROUP(NAME, ID, ALIAS) SANITIZER(NAME, ID) |
| 45 | |
| 46 | #include "clang/Basic/Sanitizers.def" |
| 47 | #undef SANITIZER |
| 48 | #undef SANITIZER_GROUP |
| 49 | |
| 50 | SanitizerSections.emplace_back(Mask, S.Entries); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | bool SanitizerSpecialCaseList::inSection(SanitizerMask Mask, StringRef Prefix, |
| 55 | StringRef Query, |
| 56 | StringRef Category) const { |
| 57 | for (auto &S : SanitizerSections) |
| 58 | if ((S.Mask & Mask) && |
Mitch Phillips | 512fa40 | 2017-11-07 21:16:37 +0000 | [diff] [blame] | 59 | SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category)) |
Vlad Tsyrklevich | 2eccdab | 2017-09-25 22:11:12 +0000 | [diff] [blame] | 60 | return true; |
| 61 | |
| 62 | return false; |
| 63 | } |