| 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 |
|
| 20 |
using namespace clang; |
| 21 |
|
| 22 |
NoSanitizeList::NoSanitizeList(const std::vector<std::string> &NoSanitizePaths, |
| 23 |
SourceManager &SM) |
| 24 |
: SSCL(SanitizerSpecialCaseList::createOrDie( |
| 25 |
NoSanitizePaths, SM.getFileManager().getVirtualFileSystem())), |
| 26 |
SM(SM) {} |
| 27 |
|
| 28 |
NoSanitizeList::~NoSanitizeList() = default; |
| 29 |
|
| 30 |
bool NoSanitizeList::containsPrefix(SanitizerMask Mask, StringRef Prefix, |
| 31 |
StringRef Name, StringRef Category) const { |
| 32 |
std::pair<unsigned, unsigned> NoSan = |
| 33 |
SSCL->inSectionBlame(Mask, Prefix, Name, Category); |
| 34 |
if (NoSan == llvm::SpecialCaseList::NotFound) |
| 35 |
return false; |
| 36 |
std::pair<unsigned, unsigned> San = |
| 37 |
SSCL->inSectionBlame(Mask, Prefix, Name, "sanitize"); |
| 38 |
// The statement evaluates to true under the following conditions: |
| 39 |
// 1. The string "prefix:*=sanitize" is absent. |
| 40 |
// 2. If "prefix:*=sanitize" is present, its (File Index, Line Number) is less |
| 41 |
// than that of "prefix:*". |
| 42 |
return San == llvm::SpecialCaseList::NotFound || NoSan > San; |
| 43 |
} |
| 44 |
|
| 45 |
bool NoSanitizeList::containsGlobal(SanitizerMask Mask, StringRef GlobalName, |
| 46 |
StringRef Category) const { |
| 47 |
return containsPrefix(Mask, "global", GlobalName, Category); |
| 48 |
} |
| 49 |
|
| 50 |
bool NoSanitizeList::containsType(SanitizerMask Mask, StringRef MangledTypeName, |
| 51 |
StringRef Category) const { |
| 52 |
return containsPrefix(Mask, "type", MangledTypeName, Category); |
| 53 |
} |
| 54 |
|
| 55 |
bool NoSanitizeList::containsFunction(SanitizerMask Mask, |
| 56 |
StringRef FunctionName) const { |
| 57 |
return containsPrefix(Mask, "fun", FunctionName, {}); |
| 58 |
} |
| 59 |
|
| 60 |
bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName, |
| 61 |
StringRef Category) const { |
| 62 |
return containsPrefix(Mask, "src", FileName, Category); |
| 63 |
} |
| 64 |
|
| 65 |
bool NoSanitizeList::containsMainFile(SanitizerMask Mask, StringRef FileName, |
| 66 |
StringRef Category) const { |
| 67 |
return containsPrefix(Mask, "mainfile", FileName, Category); |
| 68 |
} |
| 69 |
|
| 70 |
bool NoSanitizeList::containsLocation(SanitizerMask Mask, SourceLocation Loc, |
| 71 |
StringRef Category) const { |
| 72 |
return Loc.isValid() && |
| 73 |
containsFile(Mask, SM.getFilename(SM.getFileLoc(Loc)), Category); |
| 74 |
} |