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 | 8d043e82ef1179fed1d3d85171905c55bda7312f (patch) | |
| tree | 25fb71f5b38e28f2818c4c4eb8b5e18144923bbf /clang/lib/Basic | |
| parent | aac82c4849ec487c523e9cdaff4fadb65f4cf6e2 (diff) | |
| download | bcm5719-llvm-8d043e82ef1179fed1d3d85171905c55bda7312f.tar.gz bcm5719-llvm-8d043e82ef1179fed1d3d85171905c55bda7312f.zip | |
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.
llvm-svn: 219840
Diffstat (limited to 'clang/lib/Basic')
| -rw-r--r-- | clang/lib/Basic/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | clang/lib/Basic/SanitizerBlacklist.cpp | 51 |
2 files changed, 52 insertions, 0 deletions
diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt index 0df82b3bc90..e04417d1cf5 100644 --- a/clang/lib/Basic/CMakeLists.txt +++ b/clang/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/clang/lib/Basic/SanitizerBlacklist.cpp b/clang/lib/Basic/SanitizerBlacklist.cpp new file mode 100644 index 00000000000..f96ebc0d9dd --- /dev/null +++ b/clang/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); +} |

