r212643 - Decouple llvm::SpecialCaseList text representation and its LLVM IR semantics.
Alexey Samsonov
vonosmas at gmail.com
Wed Jul 9 12:40:08 PDT 2014
Author: samsonov
Date: Wed Jul 9 14:40:08 2014
New Revision: 212643
URL: http://llvm.org/viewvc/llvm-project?rev=212643&view=rev
Log:
Decouple llvm::SpecialCaseList text representation and its LLVM IR semantics.
Turn llvm::SpecialCaseList into a simple class that parses text files in
a specified format and knows nothing about LLVM IR. Move this class into
LLVMSupport library. Implement two users of this class:
* DFSanABIList in DFSan instrumentation pass.
* SanitizerBlacklist in Clang CodeGen library.
The latter will be modified to use actual source-level information from frontend
(source file names) instead of unstable LLVM IR things (LLVM Module identifier).
Remove dependency edge from ClangCodeGen/ClangDriver to LLVMTransformUtils.
No functionality change.
Added:
cfe/trunk/lib/CodeGen/SanitizerBlacklist.cpp
cfe/trunk/lib/CodeGen/SanitizerBlacklist.h
Modified:
cfe/trunk/lib/CodeGen/CMakeLists.txt
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/Driver/CMakeLists.txt
cfe/trunk/lib/Driver/SanitizerArgs.cpp
Modified: cfe/trunk/lib/CodeGen/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CMakeLists.txt?rev=212643&r1=212642&r2=212643&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CMakeLists.txt (original)
+++ cfe/trunk/lib/CodeGen/CMakeLists.txt Wed Jul 9 14:40:08 2014
@@ -13,7 +13,6 @@ set(LLVM_LINK_COMPONENTS
ScalarOpts
Support
Target
- TransformUtils
)
add_clang_library(clangCodeGen
@@ -60,6 +59,7 @@ add_clang_library(clangCodeGen
ItaniumCXXABI.cpp
MicrosoftCXXABI.cpp
ModuleBuilder.cpp
+ SanitizerBlacklist.cpp
TargetInfo.cpp
DEPENDS
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=212643&r1=212642&r2=212643&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Jul 9 14:40:08 2014
@@ -87,9 +87,8 @@ CodeGenModule::CodeGenModule(ASTContext
NSConcreteStackBlock(nullptr), BlockObjectAssign(nullptr),
BlockObjectDispose(nullptr), BlockDescriptorType(nullptr),
GenericBlockLiteralType(nullptr), LifetimeStartFn(nullptr),
- LifetimeEndFn(nullptr),
- SanitizerBlacklist(
- llvm::SpecialCaseList::createOrDie(CGO.SanitizerBlacklistFile)) {
+ LifetimeEndFn(nullptr), SanitizerBL(llvm::SpecialCaseList::createOrDie(
+ CGO.SanitizerBlacklistFile)) {
// Initialize the type cache.
llvm::LLVMContext &LLVMContext = M.getContext();
@@ -730,7 +729,7 @@ void CodeGenModule::SetLLVMFunctionAttri
B.addAttribute(llvm::Attribute::StackProtectReq);
// Add sanitizer attributes if function is not blacklisted.
- if (!SanitizerBlacklist->isIn(*F)) {
+ if (!SanitizerBL.isIn(*F)) {
// When AddressSanitizer is enabled, set SanitizeAddress attribute
// unless __attribute__((no_sanitize_address)) is used.
if (LangOpts.Sanitize.Address && !D->hasAttr<NoSanitizeAddressAttr>())
@@ -1965,8 +1964,8 @@ void CodeGenModule::reportGlobalToASan(l
SourceLocation Loc, bool IsDynInit) {
if (!LangOpts.Sanitize.Address)
return;
- IsDynInit &= !SanitizerBlacklist->isIn(*GV, "init");
- bool IsBlacklisted = SanitizerBlacklist->isIn(*GV);
+ IsDynInit &= !SanitizerBL.isIn(*GV, "init");
+ bool IsBlacklisted = SanitizerBL.isIn(*GV);
llvm::LLVMContext &LLVMCtx = TheModule.getContext();
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=212643&r1=212642&r2=212643&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Wed Jul 9 14:40:08 2014
@@ -16,6 +16,7 @@
#include "CGVTables.h"
#include "CodeGenTypes.h"
+#include "SanitizerBlacklist.h"
#include "clang/AST/Attr.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
@@ -31,7 +32,6 @@
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ValueHandle.h"
-#include "llvm/Transforms/Utils/SpecialCaseList.h"
namespace llvm {
class Module;
@@ -473,7 +473,7 @@ class CodeGenModule : public CodeGenType
GlobalDecl initializedGlobalDecl;
- std::unique_ptr<llvm::SpecialCaseList> SanitizerBlacklist;
+ SanitizerBlacklist SanitizerBL;
/// @}
public:
@@ -1008,8 +1008,8 @@ public:
/// annotations are emitted during finalization of the LLVM code.
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
- const llvm::SpecialCaseList &getSanitizerBlacklist() const {
- return *SanitizerBlacklist;
+ const SanitizerBlacklist &getSanitizerBlacklist() const {
+ return SanitizerBL;
}
void reportGlobalToASan(llvm::GlobalVariable *GV, SourceLocation Loc,
Added: cfe/trunk/lib/CodeGen/SanitizerBlacklist.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/SanitizerBlacklist.cpp?rev=212643&view=auto
==============================================================================
--- cfe/trunk/lib/CodeGen/SanitizerBlacklist.cpp (added)
+++ cfe/trunk/lib/CodeGen/SanitizerBlacklist.cpp Wed Jul 9 14:40:08 2014
@@ -0,0 +1,48 @@
+//===--- 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);
+}
Added: cfe/trunk/lib/CodeGen/SanitizerBlacklist.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/SanitizerBlacklist.h?rev=212643&view=auto
==============================================================================
--- cfe/trunk/lib/CodeGen/SanitizerBlacklist.h (added)
+++ cfe/trunk/lib/CodeGen/SanitizerBlacklist.h Wed Jul 9 14:40:08 2014
@@ -0,0 +1,45 @@
+//===--- SanitizerBlacklist.h - Blacklist for sanitizers --------*- C++ -*-===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+#ifndef CLANG_CODEGEN_SANITIZERBLACKLIST_H
+#define CLANG_CODEGEN_SANITIZERBLACKLIST_H
+
+#include "clang/Basic/LLVM.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/SpecialCaseList.h"
+#include <memory>
+
+namespace llvm {
+class GlobalVariable;
+class Function;
+class Module;
+}
+
+namespace clang {
+namespace CodeGen {
+
+class SanitizerBlacklist {
+ std::unique_ptr<llvm::SpecialCaseList> SCL;
+
+public:
+ SanitizerBlacklist(llvm::SpecialCaseList *SCL) : SCL(SCL) {}
+ bool isIn(const llvm::Module &M,
+ const StringRef Category = StringRef()) const;
+ bool isIn(const llvm::Function &F) const;
+ bool isIn(const llvm::GlobalVariable &G,
+ const StringRef Category = StringRef()) const;
+};
+} // end namespace CodeGen
+} // end namespace clang
+
+#endif
Modified: cfe/trunk/lib/Driver/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/CMakeLists.txt?rev=212643&r1=212642&r2=212643&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/CMakeLists.txt (original)
+++ cfe/trunk/lib/Driver/CMakeLists.txt Wed Jul 9 14:40:08 2014
@@ -1,7 +1,6 @@
set(LLVM_LINK_COMPONENTS
Option
Support
- TransformUtils
)
add_clang_library(clangDriver
Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=212643&r1=212642&r2=212643&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Wed Jul 9 14:40:08 2014
@@ -15,7 +15,7 @@
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
-#include "llvm/Transforms/Utils/SpecialCaseList.h"
+#include "llvm/Support/SpecialCaseList.h"
#include <memory>
using namespace clang::driver;
More information about the cfe-commits
mailing list