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