blob: 5bf8d39ffd95bbb5c84869adf4f55ee997544ad8 [file] [log] [blame]
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +00001//===--- SanitizerSpecialCaseList.cpp - SCL for sanitizers ----------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Tsyrklevich2eccdab2017-09-25 22:11:12 +00006//
7//===----------------------------------------------------------------------===//
8//
9// An extension of SpecialCaseList to allowing querying sections by
10// SanitizerMask.
11//
12//===----------------------------------------------------------------------===//
13#include "clang/Basic/SanitizerSpecialCaseList.h"
14
15using namespace clang;
16
17std::unique_ptr<SanitizerSpecialCaseList>
18SanitizerSpecialCaseList::create(const std::vector<std::string> &Paths,
Jan Korous590f2792019-11-08 10:40:27 -080019 llvm::vfs::FileSystem &VFS,
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000020 std::string &Error) {
21 std::unique_ptr<clang::SanitizerSpecialCaseList> SSCL(
22 new SanitizerSpecialCaseList());
Ilya Biryukovaa981c12019-11-21 11:32:17 +010023 if (SSCL->createInternal(Paths, VFS, Error)) {
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000024 SSCL->createSanitizerSections();
25 return SSCL;
26 }
27 return nullptr;
28}
29
30std::unique_ptr<SanitizerSpecialCaseList>
Jan Korous590f2792019-11-08 10:40:27 -080031SanitizerSpecialCaseList::createOrDie(const std::vector<std::string> &Paths,
32 llvm::vfs::FileSystem &VFS) {
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000033 std::string Error;
Jan Korous590f2792019-11-08 10:40:27 -080034 if (auto SSCL = create(Paths, VFS, Error))
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000035 return SSCL;
36 llvm::report_fatal_error(Error);
37}
38
39void SanitizerSpecialCaseList::createSanitizerSections() {
40 for (auto &S : Sections) {
Pierre Gousseauae5303d2019-03-01 10:05:15 +000041 SanitizerMask Mask;
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000042
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
56bool SanitizerSpecialCaseList::inSection(SanitizerMask Mask, StringRef Prefix,
57 StringRef Query,
58 StringRef Category) const {
59 for (auto &S : SanitizerSections)
60 if ((S.Mask & Mask) &&
Mitch Phillips512fa402017-11-07 21:16:37 +000061 SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category))
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000062 return true;
63
64 return false;
65}