1//===--- SanitizerBlacklist.cpp - Blacklist 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 blacklist used to disable/alter instrumentation done in
10// sanitizers.
11//
12//===----------------------------------------------------------------------===//
13#include "clang/Basic/SanitizerBlacklist.h"
14
15using namespace clang;
16
17SanitizerBlacklist::SanitizerBlacklist(
18    const std::vector<std::string> &BlacklistPaths, SourceManager &SM)
19    : SSCL(SanitizerSpecialCaseList::createOrDie(
20          BlacklistPaths, SM.getFileManager().getVirtualFileSystem())),
21      SM(SM) {}
22
23bool SanitizerBlacklist::isBlacklistedGlobal(SanitizerMask Mask,
24                                             StringRef GlobalName,
25                                             StringRef Category) const {
26  return SSCL->inSection(Mask, "global", GlobalName, Category);
27}
28
29bool SanitizerBlacklist::isBlacklistedType(SanitizerMask Mask,
30                                           StringRef MangledTypeName,
31                                           StringRef Category) const {
32  return SSCL->inSection(Mask, "type", MangledTypeName, Category);
33}
34
35bool SanitizerBlacklist::isBlacklistedFunction(SanitizerMask Mask,
36                                               StringRef FunctionName) const {
37  return SSCL->inSection(Mask, "fun", FunctionName);
38}
39
40bool SanitizerBlacklist::isBlacklistedFile(SanitizerMask Mask,
41                                           StringRef FileName,
42                                           StringRef Category) const {
43  return SSCL->inSection(Mask, "src", FileName, Category);
44}
45
46bool SanitizerBlacklist::isBlacklistedLocation(SanitizerMask Mask,
47                                               SourceLocation Loc,
48                                               StringRef Category) const {
49  return Loc.isValid() &&
50         isBlacklistedFile(Mask, SM.getFilename(SM.getFileLoc(Loc)), Category);
51}
52
53