blob: e042db92b4c6f2e7bf779578763df913aee6c321 [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,
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
29std::unique_ptr<SanitizerSpecialCaseList>
30SanitizerSpecialCaseList::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
37void SanitizerSpecialCaseList::createSanitizerSections() {
38 for (auto &S : Sections) {
39 SanitizerMask Mask = 0;
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
54bool SanitizerSpecialCaseList::inSection(SanitizerMask Mask, StringRef Prefix,
55 StringRef Query,
56 StringRef Category) const {
57 for (auto &S : SanitizerSections)
58 if ((S.Mask & Mask) &&
Mitch Phillips512fa402017-11-07 21:16:37 +000059 SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category))
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +000060 return true;
61
62 return false;
63}