summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/clang/lib/CodeGen/SanitizerBlacklist.cpp
blob: 9f1ddc8e7d7b9e8b87e2e0b4494d846a9cc20153 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//===--- SanitizerBlacklist.cpp - Blacklist for sanitizers ----------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// User-provided blacklist used to disable/alter instrumentation done in
// sanitizers.
//
//===----------------------------------------------------------------------===//
#include "SanitizerBlacklist.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/Module.h"

using namespace clang;
using namespace CodeGen;

static StringRef GetGlobalTypeString(const llvm::GlobalValue &G) {
  // Types of GlobalVariables are always pointer types.
  llvm::Type *GType = G.getType()->getElementType();
  // For now we support blacklisting struct types only.
  if (llvm::StructType *SGType = dyn_cast<llvm::StructType>(GType)) {
    if (!SGType->isLiteral())
      return SGType->getName();
  }
  return "<unknown type>";
}

bool SanitizerBlacklist::isIn(const llvm::Module &M,
                              const StringRef Category) const {
  return SCL->inSection("src", M.getModuleIdentifier(), Category);
}

bool SanitizerBlacklist::isIn(const llvm::Function &F) const {
  return isIn(*F.getParent()) ||
         SCL->inSection("fun", F.getName(), "");
}

bool SanitizerBlacklist::isIn(const llvm::GlobalVariable &G,
                              const StringRef Category) const {
  return isIn(*G.getParent(), Category) ||
         SCL->inSection("global", G.getName(), Category) ||
         SCL->inSection("type", GetGlobalTypeString(G), Category);
}

bool SanitizerBlacklist::isBlacklistedType(StringRef MangledTypeName) const {
  return SCL->inSection("type", MangledTypeName);
}
OpenPOWER on IntegriCloud