diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -34,10 +34,10 @@ #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/Linkage.h" +#include "clang/Basic/NoSanitizeList.h" #include "clang/Basic/OperatorKinds.h" #include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/ProfileList.h" -#include "clang/Basic/SanitizerBlacklist.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/Specifiers.h" #include "clang/Basic/XRayLists.h" @@ -562,9 +562,9 @@ /// this ASTContext object. LangOptions &LangOpts; - /// Blacklist object that is used by sanitizers to decide which + /// NoSanitizeList object that is used by sanitizers to decide which /// entities should not be instrumented. - std::unique_ptr SanitizerBL; + std::unique_ptr NoSanitizeL; /// Function filtering mechanism to determine whether a given function /// should be imbued with the XRay "always" or "never" attributes. @@ -691,9 +691,7 @@ return LangOpts.CPlusPlus || LangOpts.RecoveryAST; } - const SanitizerBlacklist &getSanitizerBlacklist() const { - return *SanitizerBL; - } + const NoSanitizeList &getNoSanitizeList() const { return *NoSanitizeL; } const XRayFunctionFilter &getXRayFilter() const { return *XRayFilter; diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -264,9 +264,9 @@ /// Set of enabled sanitizers. SanitizerSet Sanitize; - /// Paths to blacklist files specifying which objects + /// Paths to files specifying which objects /// (files, functions, variables) should not be instrumented. - std::vector SanitizerBlacklistFiles; + std::vector NoSanitizeFiles; /// Paths to the XRay "always instrument" files specifying which /// objects (files, functions, variables) should be imbued with the XRay diff --git a/clang/include/clang/Basic/NoSanitizeList.h b/clang/include/clang/Basic/NoSanitizeList.h new file mode 100644 --- /dev/null +++ b/clang/include/clang/Basic/NoSanitizeList.h @@ -0,0 +1,50 @@ +//===--- NoSanitizeList.h - List of ignored entities for sanitizers --*- C++ +//-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// User-provided list of ignored entities used to disable/alter +// instrumentation done in sanitizers. +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_CLANG_BASIC_NOSANITIZELIST_H +#define LLVM_CLANG_BASIC_NOSANITIZELIST_H + +#include "clang/Basic/LLVM.h" +#include "clang/Basic/SourceLocation.h" +#include "llvm/ADT/StringRef.h" +#include +#include + +namespace clang { + +class SanitizerMask; +class SourceManager; +class SanitizerSpecialCaseList; + +class NoSanitizeList { + std::unique_ptr SSCL; + SourceManager &SM; + +public: + NoSanitizeList(const std::vector &NoSanitizeListPaths, + SourceManager &SM); + ~NoSanitizeList(); + bool containsGlobal(SanitizerMask Mask, StringRef GlobalName, + StringRef Category = StringRef()) const; + bool containsType(SanitizerMask Mask, StringRef MangledTypeName, + StringRef Category = StringRef()) const; + bool containsFunction(SanitizerMask Mask, StringRef FunctionName) const; + bool containsFile(SanitizerMask Mask, StringRef FileName, + StringRef Category = StringRef()) const; + bool containsLocation(SanitizerMask Mask, SourceLocation Loc, + StringRef Category = StringRef()) const; +}; + +} // end namespace clang + +#endif diff --git a/clang/include/clang/Basic/SanitizerBlacklist.h b/clang/include/clang/Basic/SanitizerBlacklist.h deleted file mode 100644 --- a/clang/include/clang/Basic/SanitizerBlacklist.h +++ /dev/null @@ -1,49 +0,0 @@ -//===--- SanitizerBlacklist.h - Blacklist for sanitizers --------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// User-provided blacklist used to disable/alter instrumentation done in -// sanitizers. -// -//===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_BASIC_SANITIZERBLACKLIST_H -#define LLVM_CLANG_BASIC_SANITIZERBLACKLIST_H - -#include "clang/Basic/LLVM.h" -#include "clang/Basic/SourceLocation.h" -#include "llvm/ADT/StringRef.h" -#include -#include - -namespace clang { - -class SanitizerMask; -class SourceManager; -class SanitizerSpecialCaseList; - -class SanitizerBlacklist { - std::unique_ptr SSCL; - SourceManager &SM; - -public: - SanitizerBlacklist(const std::vector &BlacklistPaths, - SourceManager &SM); - ~SanitizerBlacklist(); - bool isBlacklistedGlobal(SanitizerMask Mask, StringRef GlobalName, - StringRef Category = StringRef()) const; - bool isBlacklistedType(SanitizerMask Mask, StringRef MangledTypeName, - StringRef Category = StringRef()) const; - bool isBlacklistedFunction(SanitizerMask Mask, StringRef FunctionName) const; - bool isBlacklistedFile(SanitizerMask Mask, StringRef FileName, - StringRef Category = StringRef()) const; - bool isBlacklistedLocation(SanitizerMask Mask, SourceLocation Loc, - StringRef Category = StringRef()) const; -}; - -} // end namespace clang - -#endif diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -56,8 +56,8 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/Linkage.h" #include "clang/Basic/Module.h" +#include "clang/Basic/NoSanitizeList.h" #include "clang/Basic/ObjCRuntime.h" -#include "clang/Basic/SanitizerBlacklist.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/Specifiers.h" @@ -961,7 +961,7 @@ DependentTemplateSpecializationTypes(this_()), AutoTypes(this_()), SubstTemplateTemplateParmPacks(this_()), CanonTemplateTemplateParms(this_()), SourceMgr(SM), LangOpts(LOpts), - SanitizerBL(new SanitizerBlacklist(LangOpts.SanitizerBlacklistFiles, SM)), + NoSanitizeL(new NoSanitizeList(LangOpts.NoSanitizeFiles, SM)), XRayFilter(new XRayFunctionFilter(LangOpts.XRayAlwaysInstrumentFiles, LangOpts.XRayNeverInstrumentFiles, LangOpts.XRayAttrListFiles, SM)), diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -41,8 +41,8 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/Linkage.h" #include "clang/Basic/Module.h" +#include "clang/Basic/NoSanitizeList.h" #include "clang/Basic/PartialDiagnostic.h" -#include "clang/Basic/SanitizerBlacklist.h" #include "clang/Basic/Sanitizers.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" @@ -4594,7 +4594,7 @@ (SanitizerKind::Address | SanitizerKind::KernelAddress); if (!EnabledAsanMask || !Context.getLangOpts().SanitizeAddressFieldPadding) return false; - const auto &Blacklist = Context.getSanitizerBlacklist(); + const auto &NoSanitizeList = Context.getNoSanitizeList(); const auto *CXXRD = dyn_cast(this); // We may be able to relax some of these requirements. int ReasonToReject = -1; @@ -4610,12 +4610,11 @@ ReasonToReject = 4; // has trivial destructor. else if (CXXRD->isStandardLayout()) ReasonToReject = 5; // is standard layout. - else if (Blacklist.isBlacklistedLocation(EnabledAsanMask, getLocation(), + else if (NoSanitizeList.containsLocation(EnabledAsanMask, getLocation(), "field-padding")) ReasonToReject = 6; // is in an excluded file. - else if (Blacklist.isBlacklistedType(EnabledAsanMask, - getQualifiedNameAsString(), - "field-padding")) + else if (NoSanitizeList.containsType( + EnabledAsanMask, getQualifiedNameAsString(), "field-padding")) ReasonToReject = 7; // The type is excluded. if (EmitRemark) { diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt --- a/clang/lib/Basic/CMakeLists.txt +++ b/clang/lib/Basic/CMakeLists.txt @@ -60,7 +60,7 @@ OpenMPKinds.cpp OperatorPrecedence.cpp ProfileList.cpp - SanitizerBlacklist.cpp + NoSanitizeList.cpp SanitizerSpecialCaseList.cpp Sanitizers.cpp SourceLocation.cpp diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp --- a/clang/lib/Basic/LangOptions.cpp +++ b/clang/lib/Basic/LangOptions.cpp @@ -28,7 +28,7 @@ #include "clang/Basic/LangOptions.def" // These options do not affect AST generation. - SanitizerBlacklistFiles.clear(); + NoSanitizeFiles.clear(); XRayAlwaysInstrumentFiles.clear(); XRayNeverInstrumentFiles.clear(); diff --git a/clang/lib/Basic/NoSanitizeList.cpp b/clang/lib/Basic/NoSanitizeList.cpp new file mode 100644 --- /dev/null +++ b/clang/lib/Basic/NoSanitizeList.cpp @@ -0,0 +1,54 @@ +//===--- NoSanitizeList.cpp - Ignored list for sanitizers ----------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// User-provided ignore-list used to disable/alter instrumentation done in +// sanitizers. +// +//===----------------------------------------------------------------------===// + +#include "clang/Basic/NoSanitizeList.h" +#include "clang/Basic/FileManager.h" +#include "clang/Basic/SanitizerSpecialCaseList.h" +#include "clang/Basic/Sanitizers.h" +#include "clang/Basic/SourceManager.h" + +using namespace clang; + +NoSanitizeList::NoSanitizeList(const std::vector &NoSanitizePaths, + SourceManager &SM) + : SSCL(SanitizerSpecialCaseList::createOrDie( + NoSanitizePaths, SM.getFileManager().getVirtualFileSystem())), + SM(SM) {} + +NoSanitizeList::~NoSanitizeList() = default; + +bool NoSanitizeList::containsGlobal(SanitizerMask Mask, StringRef GlobalName, + StringRef Category) const { + return SSCL->inSection(Mask, "global", GlobalName, Category); +} + +bool NoSanitizeList::containsType(SanitizerMask Mask, StringRef MangledTypeName, + StringRef Category) const { + return SSCL->inSection(Mask, "type", MangledTypeName, Category); +} + +bool NoSanitizeList::containsFunction(SanitizerMask Mask, + StringRef FunctionName) const { + return SSCL->inSection(Mask, "fun", FunctionName); +} + +bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName, + StringRef Category) const { + return SSCL->inSection(Mask, "src", FileName, Category); +} + +bool NoSanitizeList::containsLocation(SanitizerMask Mask, SourceLocation Loc, + StringRef Category) const { + return Loc.isValid() && + containsFile(Mask, SM.getFilename(SM.getFileLoc(Loc)), Category); +} diff --git a/clang/lib/Basic/SanitizerBlacklist.cpp b/clang/lib/Basic/SanitizerBlacklist.cpp deleted file mode 100644 --- a/clang/lib/Basic/SanitizerBlacklist.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//===--- SanitizerBlacklist.cpp - Blacklist for sanitizers ----------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// User-provided blacklist used to disable/alter instrumentation done in -// sanitizers. -// -//===----------------------------------------------------------------------===// - -#include "clang/Basic/SanitizerBlacklist.h" -#include "clang/Basic/FileManager.h" -#include "clang/Basic/SanitizerSpecialCaseList.h" -#include "clang/Basic/Sanitizers.h" -#include "clang/Basic/SourceManager.h" - -using namespace clang; - -SanitizerBlacklist::SanitizerBlacklist( - const std::vector &BlacklistPaths, SourceManager &SM) - : SSCL(SanitizerSpecialCaseList::createOrDie( - BlacklistPaths, SM.getFileManager().getVirtualFileSystem())), - SM(SM) {} - -SanitizerBlacklist::~SanitizerBlacklist() = default; - -bool SanitizerBlacklist::isBlacklistedGlobal(SanitizerMask Mask, - StringRef GlobalName, - StringRef Category) const { - return SSCL->inSection(Mask, "global", GlobalName, Category); -} - -bool SanitizerBlacklist::isBlacklistedType(SanitizerMask Mask, - StringRef MangledTypeName, - StringRef Category) const { - return SSCL->inSection(Mask, "type", MangledTypeName, Category); -} - -bool SanitizerBlacklist::isBlacklistedFunction(SanitizerMask Mask, - StringRef FunctionName) const { - return SSCL->inSection(Mask, "fun", FunctionName); -} - -bool SanitizerBlacklist::isBlacklistedFile(SanitizerMask Mask, - StringRef FileName, - StringRef Category) const { - return SSCL->inSection(Mask, "src", FileName, Category); -} - -bool SanitizerBlacklist::isBlacklistedLocation(SanitizerMask Mask, - SourceLocation Loc, - StringRef Category) const { - return Loc.isValid() && - isBlacklistedFile(Mask, SM.getFilename(SM.getFileLoc(Loc)), Category); -} - diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -362,8 +362,7 @@ const PassManagerBuilderWrapper &BuilderWrapper = static_cast(Builder); const LangOptions &LangOpts = BuilderWrapper.getLangOpts(); - PM.add( - createDataFlowSanitizerLegacyPassPass(LangOpts.SanitizerBlacklistFiles)); + PM.add(createDataFlowSanitizerLegacyPassPass(LangOpts.NoSanitizeFiles)); } static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple, @@ -1132,7 +1131,7 @@ HWASanPass(SanitizerKind::KernelHWAddress, true); if (LangOpts.Sanitize.has(SanitizerKind::DataFlow)) { - MPM.addPass(DataFlowSanitizerPass(LangOpts.SanitizerBlacklistFiles)); + MPM.addPass(DataFlowSanitizerPass(LangOpts.NoSanitizeFiles)); } }); } diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -2776,7 +2776,7 @@ } std::string TypeName = RD->getQualifiedNameAsString(); - if (getContext().getSanitizerBlacklist().isBlacklistedType(M, TypeName)) + if (getContext().getNoSanitizeList().containsType(M, TypeName)) return; SanitizerScope SanScope(this); @@ -2829,8 +2829,8 @@ return false; std::string TypeName = RD->getQualifiedNameAsString(); - return !getContext().getSanitizerBlacklist().isBlacklistedType( - SanitizerKind::CFIVCall, TypeName); + return !getContext().getNoSanitizeList().containsType(SanitizerKind::CFIVCall, + TypeName); } llvm::Value *CodeGenFunction::EmitVTableTypeCheckedLoad( @@ -2852,8 +2852,8 @@ std::string TypeName = RD->getQualifiedNameAsString(); if (SanOpts.has(SanitizerKind::CFIVCall) && - !getContext().getSanitizerBlacklist().isBlacklistedType( - SanitizerKind::CFIVCall, TypeName)) { + !getContext().getNoSanitizeList().containsType(SanitizerKind::CFIVCall, + TypeName)) { EmitCheck(std::make_pair(CheckResult, SanitizerKind::CFIVCall), SanitizerHandler::CFICheckFail, {}, {}); } diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp --- a/clang/lib/CodeGen/CGDeclCXX.cpp +++ b/clang/lib/CodeGen/CGDeclCXX.cpp @@ -388,43 +388,43 @@ Fn->setDoesNotThrow(); if (getLangOpts().Sanitize.has(SanitizerKind::Address) && - !isInSanitizerBlacklist(SanitizerKind::Address, Fn, Loc)) + !isInNoSanitizeList(SanitizerKind::Address, Fn, Loc)) Fn->addFnAttr(llvm::Attribute::SanitizeAddress); if (getLangOpts().Sanitize.has(SanitizerKind::KernelAddress) && - !isInSanitizerBlacklist(SanitizerKind::KernelAddress, Fn, Loc)) + !isInNoSanitizeList(SanitizerKind::KernelAddress, Fn, Loc)) Fn->addFnAttr(llvm::Attribute::SanitizeAddress); if (getLangOpts().Sanitize.has(SanitizerKind::HWAddress) && - !isInSanitizerBlacklist(SanitizerKind::HWAddress, Fn, Loc)) + !isInNoSanitizeList(SanitizerKind::HWAddress, Fn, Loc)) Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress); if (getLangOpts().Sanitize.has(SanitizerKind::KernelHWAddress) && - !isInSanitizerBlacklist(SanitizerKind::KernelHWAddress, Fn, Loc)) + !isInNoSanitizeList(SanitizerKind::KernelHWAddress, Fn, Loc)) Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress); if (getLangOpts().Sanitize.has(SanitizerKind::MemTag) && - !isInSanitizerBlacklist(SanitizerKind::MemTag, Fn, Loc)) + !isInNoSanitizeList(SanitizerKind::MemTag, Fn, Loc)) Fn->addFnAttr(llvm::Attribute::SanitizeMemTag); if (getLangOpts().Sanitize.has(SanitizerKind::Thread) && - !isInSanitizerBlacklist(SanitizerKind::Thread, Fn, Loc)) + !isInNoSanitizeList(SanitizerKind::Thread, Fn, Loc)) Fn->addFnAttr(llvm::Attribute::SanitizeThread); if (getLangOpts().Sanitize.has(SanitizerKind::Memory) && - !isInSanitizerBlacklist(SanitizerKind::Memory, Fn, Loc)) + !isInNoSanitizeList(SanitizerKind::Memory, Fn, Loc)) Fn->addFnAttr(llvm::Attribute::SanitizeMemory); if (getLangOpts().Sanitize.has(SanitizerKind::KernelMemory) && - !isInSanitizerBlacklist(SanitizerKind::KernelMemory, Fn, Loc)) + !isInNoSanitizeList(SanitizerKind::KernelMemory, Fn, Loc)) Fn->addFnAttr(llvm::Attribute::SanitizeMemory); if (getLangOpts().Sanitize.has(SanitizerKind::SafeStack) && - !isInSanitizerBlacklist(SanitizerKind::SafeStack, Fn, Loc)) + !isInNoSanitizeList(SanitizerKind::SafeStack, Fn, Loc)) Fn->addFnAttr(llvm::Attribute::SafeStack); if (getLangOpts().Sanitize.has(SanitizerKind::ShadowCallStack) && - !isInSanitizerBlacklist(SanitizerKind::ShadowCallStack, Fn, Loc)) + !isInNoSanitizeList(SanitizerKind::ShadowCallStack, Fn, Loc)) Fn->addFnAttr(llvm::Attribute::ShadowCallStack); return Fn; diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -826,9 +826,9 @@ CGM.getCXXABI().getMangleContext().mangleCXXRTTI(Ty.getUnqualifiedType(), Out); - // Blacklist based on the mangled type. - if (!CGM.getContext().getSanitizerBlacklist().isBlacklistedType( - SanitizerKind::Vptr, Out.str())) { + // Contained in NoSanitizeList based on the mangled type. + if (!CGM.getContext().getNoSanitizeList().containsType(SanitizerKind::Vptr, + Out.str())) { llvm::hash_code TypeHash = hash_value(Out.str()); // Load the vptr, and compute hash_16_bytes(TypeHash, vptr). @@ -3389,7 +3389,7 @@ StartFunction(GlobalDecl(), CGM.getContext().VoidTy, F, FI, Args, SourceLocation()); - // This function should not be affected by blacklist. This function does + // This function is not affected by NoSanitizeList. This function does // not have a source location, but "src:*" would still apply. Revert any // changes to SanOpts made in StartFunction. SanOpts = CGM.getLangOpts().Sanitize; diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -711,14 +711,14 @@ CurFnInfo = &FnInfo; assert(CurFn->isDeclaration() && "Function already has body?"); - // If this function has been blacklisted for any of the enabled sanitizers, + // If this function is ignored for any of the enabled sanitizers, // disable the sanitizer for the function. do { #define SANITIZER(NAME, ID) \ if (SanOpts.empty()) \ break; \ if (SanOpts.has(SanitizerKind::ID)) \ - if (CGM.isInSanitizerBlacklist(SanitizerKind::ID, Fn, Loc)) \ + if (CGM.isInNoSanitizeList(SanitizerKind::ID, Fn, Loc)) \ SanOpts.set(SanitizerKind::ID, false); #include "clang/Basic/Sanitizers.def" diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -25,7 +25,7 @@ #include "clang/Basic/ABI.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/Module.h" -#include "clang/Basic/SanitizerBlacklist.h" +#include "clang/Basic/NoSanitizeList.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/XRayLists.h" #include "llvm/ADT/DenseMap.h" @@ -1267,12 +1267,11 @@ /// annotations are emitted during finalization of the LLVM code. void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV); - bool isInSanitizerBlacklist(SanitizerMask Kind, llvm::Function *Fn, - SourceLocation Loc) const; + bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn, + SourceLocation Loc) const; - bool isInSanitizerBlacklist(llvm::GlobalVariable *GV, SourceLocation Loc, - QualType Ty, - StringRef Category = StringRef()) const; + bool isInNoSanitizeList(llvm::GlobalVariable *GV, SourceLocation Loc, + QualType Ty, StringRef Category = StringRef()) const; /// Imbue XRay attributes to a function, applying the always/never attribute /// lists in the process. Returns true if we did imbue attributes this way, diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2459,29 +2459,28 @@ Annotations.push_back(EmitAnnotateAttr(GV, I, D->getLocation())); } -bool CodeGenModule::isInSanitizerBlacklist(SanitizerMask Kind, - llvm::Function *Fn, - SourceLocation Loc) const { - const auto &SanitizerBL = getContext().getSanitizerBlacklist(); - // Blacklist by function name. - if (SanitizerBL.isBlacklistedFunction(Kind, Fn->getName())) +bool CodeGenModule::isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn, + SourceLocation Loc) const { + const auto &NoSanitizeL = getContext().getNoSanitizeList(); + // NoSanitize by function name. + if (NoSanitizeL.containsFunction(Kind, Fn->getName())) return true; - // Blacklist by location. + // NoSanitize by location. if (Loc.isValid()) - return SanitizerBL.isBlacklistedLocation(Kind, Loc); + return NoSanitizeL.containsLocation(Kind, Loc); // If location is unknown, this may be a compiler-generated function. Assume // it's located in the main file. auto &SM = Context.getSourceManager(); if (const auto *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { - return SanitizerBL.isBlacklistedFile(Kind, MainFile->getName()); + return NoSanitizeL.containsFile(Kind, MainFile->getName()); } return false; } -bool CodeGenModule::isInSanitizerBlacklist(llvm::GlobalVariable *GV, - SourceLocation Loc, QualType Ty, - StringRef Category) const { - // For now globals can be blacklisted only in ASan and KASan. +bool CodeGenModule::isInNoSanitizeList(llvm::GlobalVariable *GV, + SourceLocation Loc, QualType Ty, + StringRef Category) const { + // For now globals can be ignored only in ASan and KASan. const SanitizerMask EnabledAsanMask = LangOpts.Sanitize.Mask & (SanitizerKind::Address | SanitizerKind::KernelAddress | @@ -2489,22 +2488,22 @@ SanitizerKind::MemTag); if (!EnabledAsanMask) return false; - const auto &SanitizerBL = getContext().getSanitizerBlacklist(); - if (SanitizerBL.isBlacklistedGlobal(EnabledAsanMask, GV->getName(), Category)) + const auto &NoSanitizeL = getContext().getNoSanitizeList(); + if (NoSanitizeL.containsGlobal(EnabledAsanMask, GV->getName(), Category)) return true; - if (SanitizerBL.isBlacklistedLocation(EnabledAsanMask, Loc, Category)) + if (NoSanitizeL.containsLocation(EnabledAsanMask, Loc, Category)) return true; // Check global type. if (!Ty.isNull()) { // Drill down the array types: if global variable of a fixed type is - // blacklisted, we also don't instrument arrays of them. + // not sanitized, we also don't instrument arrays of them. while (auto AT = dyn_cast(Ty.getTypePtr())) Ty = AT->getElementType(); Ty = Ty.getCanonicalType().getUnqualifiedType(); - // We allow to blacklist only record types (classes, structs etc.) + // Only record types (classes, structs etc.) are ignored. if (Ty->isRecordType()) { std::string TypeStr = Ty.getAsString(getContext().getPrintingPolicy()); - if (SanitizerBL.isBlacklistedType(EnabledAsanMask, TypeStr, Category)) + if (NoSanitizeL.containsType(EnabledAsanMask, TypeStr, Category)) return true; } } diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp b/clang/lib/CodeGen/SanitizerMetadata.cpp --- a/clang/lib/CodeGen/SanitizerMetadata.cpp +++ b/clang/lib/CodeGen/SanitizerMetadata.cpp @@ -1,4 +1,4 @@ -//===--- SanitizerMetadata.cpp - Blacklist for sanitizers -----------------===// +//===--- SanitizerMetadata.cpp - Ignored entities for sanitizers ----------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -34,15 +34,15 @@ bool IsExcluded) { if (!isAsanHwasanOrMemTag(CGM.getLangOpts().Sanitize)) return; - IsDynInit &= !CGM.isInSanitizerBlacklist(GV, Loc, Ty, "init"); - IsExcluded |= CGM.isInSanitizerBlacklist(GV, Loc, Ty); + IsDynInit &= !CGM.isInNoSanitizeList(GV, Loc, Ty, "init"); + IsExcluded |= CGM.isInNoSanitizeList(GV, Loc, Ty); llvm::Metadata *LocDescr = nullptr; llvm::Metadata *GlobalName = nullptr; llvm::LLVMContext &VMContext = CGM.getLLVMContext(); if (!IsExcluded) { - // Don't generate source location and global name if it is blacklisted - - // it won't be instrumented anyway. + // Don't generate source location and global name if it is on + // the NoSanitizeList - it won't be instrumented anyway. LocDescr = getLocationMetadata(Loc); if (!Name.empty()) GlobalName = llvm::MDString::get(VMContext, Name); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3607,7 +3607,7 @@ GenerateArg(Args, OPT_fsanitize_EQ, Sanitizer, SA); // Conflating '-fsanitize-system-blacklist' and '-fsanitize-blacklist'. - for (const std::string &F : Opts.SanitizerBlacklistFiles) + for (const std::string &F : Opts.NoSanitizeFiles) GenerateArg(Args, OPT_fsanitize_blacklist, F, SA); if (Opts.getClangABICompat() == LangOptions::ClangABI::Ver3_8) @@ -4006,12 +4006,11 @@ // Parse -fsanitize= arguments. parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ), Diags, Opts.Sanitize); - Opts.SanitizerBlacklistFiles = Args.getAllArgValues(OPT_fsanitize_blacklist); + Opts.NoSanitizeFiles = Args.getAllArgValues(OPT_fsanitize_blacklist); std::vector systemBlacklists = Args.getAllArgValues(OPT_fsanitize_system_blacklist); - Opts.SanitizerBlacklistFiles.insert(Opts.SanitizerBlacklistFiles.end(), - systemBlacklists.begin(), - systemBlacklists.end()); + Opts.NoSanitizeFiles.insert(Opts.NoSanitizeFiles.end(), + systemBlacklists.begin(), systemBlacklists.end()); if (Arg *A = Args.getLastArg(OPT_fclang_abi_compat_EQ)) { Opts.setClangABICompat(LangOptions::ClangABI::Latest);