r219993 - Teach SanitizerBlacklist to blacklist by SourceLocation. NFC.
Alexey Samsonov
vonosmas at gmail.com
Thu Oct 16 16:50:27 PDT 2014
Author: samsonov
Date: Thu Oct 16 18:50:26 2014
New Revision: 219993
URL: http://llvm.org/viewvc/llvm-project?rev=219993&view=rev
Log:
Teach SanitizerBlacklist to blacklist by SourceLocation. NFC.
Modified:
cfe/trunk/include/clang/Basic/SanitizerBlacklist.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/Basic/SanitizerBlacklist.cpp
Modified: cfe/trunk/include/clang/Basic/SanitizerBlacklist.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SanitizerBlacklist.h?rev=219993&r1=219992&r2=219993&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SanitizerBlacklist.h (original)
+++ cfe/trunk/include/clang/Basic/SanitizerBlacklist.h Thu Oct 16 18:50:26 2014
@@ -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 <memory>
-#include <string>
namespace llvm {
class GlobalVariable;
@@ -29,9 +30,10 @@ namespace clang {
class SanitizerBlacklist {
std::unique_ptr<llvm::SpecialCaseList> 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
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=219993&r1=219992&r2=219993&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Oct 16 18:50:26 2014
@@ -738,7 +738,7 @@ ASTContext::ASTContext(LangOptions &LOpt
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),
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=219993&r1=219992&r2=219993&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Oct 16 18:50:26 2014
@@ -3621,9 +3621,8 @@ bool RecordDecl::mayInsertExtraPadding(b
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<CXXRecordDecl>(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(b
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"))
Modified: cfe/trunk/lib/Basic/SanitizerBlacklist.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SanitizerBlacklist.cpp?rev=219993&r1=219992&r2=219993&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SanitizerBlacklist.cpp (original)
+++ cfe/trunk/lib/Basic/SanitizerBlacklist.cpp Thu Oct 16 18:50:26 2014
@@ -29,8 +29,9 @@ static StringRef GetGlobalTypeString(con
return "<unknown type>";
}
-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::isBlacklistedFi
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);
+}
+
More information about the cfe-commits
mailing list