blob: 9882a6dc41bb34654242537da0bc3544c19b2a0c [file] [log] [blame]
Alexey Samsonovb7dd3292014-07-09 19:40:08 +00001//===--- SanitizerBlacklist.cpp - Blacklist for sanitizers ----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// User-provided blacklist used to disable/alter instrumentation done in
11// sanitizers.
12//
13//===----------------------------------------------------------------------===//
14#include "SanitizerBlacklist.h"
15#include "llvm/IR/Function.h"
16#include "llvm/IR/GlobalValue.h"
17#include "llvm/IR/Module.h"
18
19using namespace clang;
20using namespace CodeGen;
21
22static 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();
29 }
30 return "<unknown type>";
31}
32
33bool SanitizerBlacklist::isIn(const llvm::Module &M,
Craig Topperbf3e3272014-08-30 16:55:52 +000034 StringRef Category) const {
Alexey Samsonovb7dd3292014-07-09 19:40:08 +000035 return SCL->inSection("src", M.getModuleIdentifier(), Category);
36}
37
38bool SanitizerBlacklist::isIn(const llvm::Function &F) const {
39 return isIn(*F.getParent()) ||
40 SCL->inSection("fun", F.getName(), "");
41}
42
43bool SanitizerBlacklist::isIn(const llvm::GlobalVariable &G,
Craig Topperbf3e3272014-08-30 16:55:52 +000044 StringRef Category) const {
Alexey Samsonovb7dd3292014-07-09 19:40:08 +000045 return isIn(*G.getParent(), Category) ||
46 SCL->inSection("global", G.getName(), Category) ||
47 SCL->inSection("type", GetGlobalTypeString(G), Category);
48}
Alexey Samsonov84856012014-07-10 22:34:19 +000049
50bool SanitizerBlacklist::isBlacklistedType(StringRef MangledTypeName) const {
51 return SCL->inSection("type", MangledTypeName);
52}