1 //===--- SanitizerBlacklist.cpp - Blacklist for sanitizers ----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // User-provided blacklist used to disable/alter instrumentation done in
13 //===----------------------------------------------------------------------===//
14 #include "SanitizerBlacklist.h"
15 #include "llvm/IR/Function.h"
16 #include "llvm/IR/GlobalValue.h"
17 #include "llvm/IR/Module.h"
19 using namespace clang;
20 using namespace CodeGen;
22 static StringRef GetGlobalTypeString(const llvm::GlobalValue &G) {
23 // Types of GlobalVariables are always pointer types.
24 llvm::Type *GType = G.getType()->getElementType();
25 // For now we support blacklisting struct types only.
26 if (llvm::StructType *SGType = dyn_cast<llvm::StructType>(GType)) {
27 if (!SGType->isLiteral())
28 return SGType->getName();
30 return "<unknown type>";
33 bool SanitizerBlacklist::isIn(const llvm::Module &M,
34 const StringRef Category) const {
35 return SCL->inSection("src", M.getModuleIdentifier(), Category);
38 bool SanitizerBlacklist::isIn(const llvm::Function &F) const {
39 return isIn(*F.getParent()) ||
40 SCL->inSection("fun", F.getName(), "");
43 bool SanitizerBlacklist::isIn(const llvm::GlobalVariable &G,
44 const StringRef Category) const {
45 return isIn(*G.getParent(), Category) ||
46 SCL->inSection("global", G.getName(), Category) ||
47 SCL->inSection("type", GetGlobalTypeString(G), Category);
50 bool SanitizerBlacklist::isBlacklistedType(StringRef MangledTypeName) const {
51 return SCL->inSection("type", MangledTypeName);