Teach SanitizerBlacklist to blacklist by SourceLocation. NFC.

llvm-svn: 219993
This commit is contained in:
Alexey Samsonov 2014-10-16 23:50:26 +00:00
parent 63f2c2cb65
commit 33e00e22da
4 changed files with 18 additions and 8 deletions

View File

@ -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

View File

@ -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),

View File

@ -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<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(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"))

View File

@ -29,8 +29,9 @@ static StringRef GetGlobalTypeString(const llvm::GlobalValue &G) {
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::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);
}