From 1a976212e2ec2994ac5ba3ef321bee81f6969b47 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 16 Oct 2014 23:50:26 +0000 Subject: [PATCH] Teach SanitizerBlacklist to blacklist by SourceLocation. NFC. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219993 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/SanitizerBlacklist.h | 8 ++++++-- lib/AST/ASTContext.cpp | 2 +- lib/AST/Decl.cpp | 5 ++--- lib/Basic/SanitizerBlacklist.cpp | 11 +++++++++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/clang/Basic/SanitizerBlacklist.h b/include/clang/Basic/SanitizerBlacklist.h index 8fa4357b75..dfe55a18eb 100644 --- a/include/clang/Basic/SanitizerBlacklist.h +++ b/include/clang/Basic/SanitizerBlacklist.h @@ -15,10 +15,11 @@ #define LLVM_CLANG_BASIC_SANITIZERBLACKLIST_H #include "clang/Basic/LLVM.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/SpecialCaseList.h" #include -#include namespace llvm { class GlobalVariable; @@ -29,9 +30,10 @@ namespace clang { class SanitizerBlacklist { std::unique_ptr SCL; + SourceManager &SM; public: - SanitizerBlacklist(const std::string &BlacklistPath); + SanitizerBlacklist(StringRef BlacklistPath, SourceManager &SM); bool isIn(const llvm::Function &F) const; bool isIn(const llvm::GlobalVariable &G, StringRef Category = StringRef()) const; @@ -40,6 +42,8 @@ public: bool isBlacklistedFunction(StringRef FunctionName) const; bool isBlacklistedFile(StringRef FileName, StringRef Category = StringRef()) const; + bool isBlacklistedLocation(SourceLocation Loc, + StringRef Category = StringRef()) const; }; } // end namespace clang diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 0c8fa2a894..8f8ae8da0d 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -738,7 +738,7 @@ ASTContext::ASTContext(LangOptions &LOpts, SourceManager &SM, BlockDescriptorExtendedType(nullptr), cudaConfigureCallDecl(nullptr), NullTypeSourceInfo(QualType()), FirstLocalImport(), LastLocalImport(), SourceMgr(SM), LangOpts(LOpts), - SanitizerBL(new SanitizerBlacklist(LangOpts.Sanitize.BlacklistFile)), + SanitizerBL(new SanitizerBlacklist(LangOpts.Sanitize.BlacklistFile, SM)), AddrSpaceMap(nullptr), Target(nullptr), PrintingPolicy(LOpts), Idents(idents), Selectors(sels), BuiltinInfo(builtins), DeclarationNames(*this), ExternalSource(nullptr), Listener(nullptr), diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index c01272ec13..0de5459a4c 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -3621,9 +3621,8 @@ bool RecordDecl::mayInsertExtraPadding(bool EmitRemark) const { if (!Context.getLangOpts().Sanitize.Address || !Context.getLangOpts().Sanitize.SanitizeAddressFieldPadding) return false; - auto &Blacklist = Context.getSanitizerBlacklist(); + const auto &Blacklist = Context.getSanitizerBlacklist(); const CXXRecordDecl *CXXRD = dyn_cast(this); - StringRef Filename = Context.getSourceManager().getFilename(getLocation()); // We may be able to relax some of these requirements. int ReasonToReject = -1; if (!CXXRD || CXXRD->isExternCContext()) @@ -3638,7 +3637,7 @@ bool RecordDecl::mayInsertExtraPadding(bool EmitRemark) const { ReasonToReject = 4; // has trivial destructor. else if (CXXRD->isStandardLayout()) ReasonToReject = 5; // is standard layout. - else if (Blacklist.isBlacklistedFile(Filename, "field-padding")) + else if (Blacklist.isBlacklistedLocation(getLocation(), "field-padding")) ReasonToReject = 6; // is in a blacklisted file. else if (Blacklist.isBlacklistedType(getQualifiedNameAsString(), "field-padding")) diff --git a/lib/Basic/SanitizerBlacklist.cpp b/lib/Basic/SanitizerBlacklist.cpp index 84ec2100b6..f0221331ed 100644 --- a/lib/Basic/SanitizerBlacklist.cpp +++ b/lib/Basic/SanitizerBlacklist.cpp @@ -29,8 +29,9 @@ static StringRef GetGlobalTypeString(const llvm::GlobalValue &G) { return ""; } -SanitizerBlacklist::SanitizerBlacklist(const std::string &BlacklistPath) - : SCL(llvm::SpecialCaseList::createOrDie(BlacklistPath)) {} +SanitizerBlacklist::SanitizerBlacklist(StringRef BlacklistPath, + SourceManager &SM) + : SCL(llvm::SpecialCaseList::createOrDie(BlacklistPath)), SM(SM) {} bool SanitizerBlacklist::isIn(const llvm::Function &F) const { return isBlacklistedFile(F.getParent()->getModuleIdentifier()) || @@ -57,3 +58,9 @@ bool SanitizerBlacklist::isBlacklistedFile(StringRef FileName, StringRef Category) const { return SCL->inSection("src", FileName, Category); } + +bool SanitizerBlacklist::isBlacklistedLocation(SourceLocation Loc, + StringRef Category) const { + return !Loc.isInvalid() && isBlacklistedFile(SM.getFilename(Loc), Category); +} + -- 2.40.0