1//===--- NoSanitizeList.cpp - Ignored list 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// User-provided ignore-list used to disable/alter instrumentation done in
10// sanitizers.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Basic/NoSanitizeList.h"
15#include "clang/Basic/FileManager.h"
16#include "clang/Basic/SanitizerSpecialCaseList.h"
17#include "clang/Basic/Sanitizers.h"
18#include "clang/Basic/SourceManager.h"
19
20using namespace clang;
21
22NoSanitizeList::NoSanitizeList(const std::vector<std::string> &NoSanitizePaths,
23 SourceManager &SM)
24 : SSCL(SanitizerSpecialCaseList::createOrDie(
25 Paths: NoSanitizePaths, VFS&: SM.getFileManager().getVirtualFileSystem())),
26 SM(SM) {}
27
28NoSanitizeList::~NoSanitizeList() = default;
29
30bool NoSanitizeList::containsGlobal(SanitizerMask Mask, StringRef GlobalName,
31 StringRef Category) const {
32 return SSCL->inSection(Mask, Prefix: "global", Query: GlobalName, Category);
33}
34
35bool NoSanitizeList::containsType(SanitizerMask Mask, StringRef MangledTypeName,
36 StringRef Category) const {
37 return SSCL->inSection(Mask, Prefix: "type", Query: MangledTypeName, Category);
38}
39
40bool NoSanitizeList::containsFunction(SanitizerMask Mask,
41 StringRef FunctionName) const {
42 return SSCL->inSection(Mask, Prefix: "fun", Query: FunctionName);
43}
44
45bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,
46 StringRef Category) const {
47 return SSCL->inSection(Mask, Prefix: "src", Query: FileName, Category);
48}
49
50bool NoSanitizeList::containsMainFile(SanitizerMask Mask, StringRef FileName,
51 StringRef Category) const {
52 return SSCL->inSection(Mask, Prefix: "mainfile", Query: FileName, Category);
53}
54
55bool NoSanitizeList::containsLocation(SanitizerMask Mask, SourceLocation Loc,
56 StringRef Category) const {
57 return Loc.isValid() &&
58 containsFile(Mask, FileName: SM.getFilename(SpellingLoc: SM.getFileLoc(Loc)), Category);
59}
60

source code of clang/lib/Basic/NoSanitizeList.cpp