diff options
author | Alexey Samsonov <vonosmas@gmail.com> | 2014-10-15 19:57:45 +0000 |
---|---|---|
committer | Alexey Samsonov <vonosmas@gmail.com> | 2014-10-15 19:57:45 +0000 |
commit | 8bb2e13a15197d424c3436c1fb83df155a1fc538 (patch) | |
tree | f834f0b62fc32c308191a9f79d01e3388ff0becc /lib/Basic | |
parent | e0dc8e2329b068fe3476cd1297239a9f098e9f12 (diff) |
Move SanitizerBlacklist to clangBasic. NFC.
This change moves SanitizerBlacklist.h from lib/CodeGen
to public Clang headers in include/clang/Basic. SanitizerBlacklist
is currently only used in CodeGen to decide which functions/modules
should be instrumented, but this will soon change as ASan will
optionally modify class layouts during AST construction
(http://reviews.llvm.org/D5687). We need blacklist machinery
to be available at this point.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219840 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic')
-rw-r--r-- | lib/Basic/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/Basic/SanitizerBlacklist.cpp | 51 |
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/Basic/CMakeLists.txt b/lib/Basic/CMakeLists.txt index 0df82b3bc9..e04417d1cf 100644 --- a/lib/Basic/CMakeLists.txt +++ b/lib/Basic/CMakeLists.txt @@ -17,6 +17,7 @@ add_clang_library(clangBasic ObjCRuntime.cpp OpenMPKinds.cpp OperatorPrecedence.cpp + SanitizerBlacklist.cpp SourceLocation.cpp SourceManager.cpp TargetInfo.cpp diff --git a/lib/Basic/SanitizerBlacklist.cpp b/lib/Basic/SanitizerBlacklist.cpp new file mode 100644 index 0000000000..f96ebc0d9d --- /dev/null +++ b/lib/Basic/SanitizerBlacklist.cpp @@ -0,0 +1,51 @@ +//===--- 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 "clang/Basic/SanitizerBlacklist.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalValue.h" +#include "llvm/IR/Module.h" + +using namespace clang; + +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, + 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, + 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); +} |