clang  16.0.0git
SanitizerSpecialCaseList.cpp
Go to the documentation of this file.
1 //===--- SanitizerSpecialCaseList.cpp - SCL for sanitizers ----------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // An extension of SpecialCaseList to allowing querying sections by
10 // SanitizerMask.
11 //
12 //===----------------------------------------------------------------------===//
14 
15 using namespace clang;
16 
17 std::unique_ptr<SanitizerSpecialCaseList>
18 SanitizerSpecialCaseList::create(const std::vector<std::string> &Paths,
19  llvm::vfs::FileSystem &VFS,
20  std::string &Error) {
21  std::unique_ptr<clang::SanitizerSpecialCaseList> SSCL(
23  if (SSCL->createInternal(Paths, VFS, 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  llvm::vfs::FileSystem &VFS) {
34  if (auto SSCL = create(Paths, VFS, Error))
35  return SSCL;
36  llvm::report_fatal_error(StringRef(Error));
37 }
38 
40  for (auto &S : Sections) {
41  SanitizerMask Mask;
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 
57  StringRef Query,
58  StringRef Category) const {
59  for (auto &S : SanitizerSections)
60  if ((S.Mask & Mask) &&
61  SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category))
62  return true;
63 
64  return false;
65 }
Error
llvm::Error Error
Definition: ByteCodeEmitter.cpp:20
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::SanitizerSpecialCaseList::createOrDie
static std::unique_ptr< SanitizerSpecialCaseList > createOrDie(const std::vector< std::string > &Paths, llvm::vfs::FileSystem &VFS)
Definition: SanitizerSpecialCaseList.cpp:31
SanitizerSpecialCaseList.h
Category
int Category
Definition: Format.cpp:2718
clang::SanitizerSpecialCaseList::create
static std::unique_ptr< SanitizerSpecialCaseList > create(const std::vector< std::string > &Paths, llvm::vfs::FileSystem &VFS, std::string &Error)
Definition: SanitizerSpecialCaseList.cpp:18
clang::SanitizerSpecialCaseList::createSanitizerSections
void createSanitizerSections()
Definition: SanitizerSpecialCaseList.cpp:39
clang::SanitizerSpecialCaseList::SanitizerSections
std::vector< SanitizerSection > SanitizerSections
Definition: SanitizerSpecialCaseList.h:58
clang
Definition: CalledOnceCheck.h:17
clang::SanitizerSpecialCaseList
Definition: SanitizerSpecialCaseList.h:32
clang::SanitizerMask
Definition: Sanitizers.h:30
clang::SanitizerSpecialCaseList::inSection
bool inSection(SanitizerMask Mask, StringRef Prefix, StringRef Query, StringRef Category=StringRef()) const
Definition: SanitizerSpecialCaseList.cpp:56