From 33e00e22dadec919bee9ce24c0099fb79b8d38a1 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. llvm-svn: 219993 --- clang/include/clang/Basic/SanitizerBlacklist.h | 8 ++++++-- clang/lib/AST/ASTContext.cpp | 2 +- clang/lib/AST/Decl.cpp | 5 ++--- clang/lib/Basic/SanitizerBlacklist.cpp | 11 +++++++++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/clang/include/clang/Basic/SanitizerBlacklist.h b/clang/include/clang/Basic/SanitizerBlacklist.h index 8fa4357..dfe55a1 100644 --- a/clang/include/clang/Basic/SanitizerBlacklist.h +++ b/clang/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/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 0c8fa2a..8f8ae8d 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/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/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index c01272e..0de5459 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/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/clang/lib/Basic/SanitizerBlacklist.cpp b/clang/lib/Basic/SanitizerBlacklist.cpp index 84ec210..f022133 100644 --- a/clang/lib/Basic/SanitizerBlacklist.cpp +++ b/clang/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.7.4