forked from OSchip/llvm-project
[Analysis/Transforms/Sanitizers] As part of using inclusive language
within the llvm project, migrate away from the use of blacklist and whitelist.
This commit is contained in:
parent
858d385578
commit
10563e16aa
|
@ -31,16 +31,16 @@ static bool isAsanHwasanOrMemTag(const SanitizerSet& SS) {
|
|||
void SanitizerMetadata::reportGlobalToASan(llvm::GlobalVariable *GV,
|
||||
SourceLocation Loc, StringRef Name,
|
||||
QualType Ty, bool IsDynInit,
|
||||
bool IsBlacklisted) {
|
||||
bool IsExcluded) {
|
||||
if (!isAsanHwasanOrMemTag(CGM.getLangOpts().Sanitize))
|
||||
return;
|
||||
IsDynInit &= !CGM.isInSanitizerBlacklist(GV, Loc, Ty, "init");
|
||||
IsBlacklisted |= CGM.isInSanitizerBlacklist(GV, Loc, Ty);
|
||||
IsExcluded |= CGM.isInSanitizerBlacklist(GV, Loc, Ty);
|
||||
|
||||
llvm::Metadata *LocDescr = nullptr;
|
||||
llvm::Metadata *GlobalName = nullptr;
|
||||
llvm::LLVMContext &VMContext = CGM.getLLVMContext();
|
||||
if (!IsBlacklisted) {
|
||||
if (!IsExcluded) {
|
||||
// Don't generate source location and global name if it is blacklisted -
|
||||
// it won't be instrumented anyway.
|
||||
LocDescr = getLocationMetadata(Loc);
|
||||
|
@ -53,7 +53,7 @@ void SanitizerMetadata::reportGlobalToASan(llvm::GlobalVariable *GV,
|
|||
llvm::ConstantAsMetadata::get(
|
||||
llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), IsDynInit)),
|
||||
llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
|
||||
llvm::Type::getInt1Ty(VMContext), IsBlacklisted))};
|
||||
llvm::Type::getInt1Ty(VMContext), IsExcluded))};
|
||||
|
||||
llvm::MDNode *ThisGlobal = llvm::MDNode::get(VMContext, GlobalMetadata);
|
||||
llvm::NamedMDNode *AsanGlobals =
|
||||
|
@ -69,12 +69,12 @@ void SanitizerMetadata::reportGlobalToASan(llvm::GlobalVariable *GV,
|
|||
llvm::raw_string_ostream OS(QualName);
|
||||
D.printQualifiedName(OS);
|
||||
|
||||
bool IsBlacklisted = false;
|
||||
bool IsExcluded = false;
|
||||
for (auto Attr : D.specific_attrs<NoSanitizeAttr>())
|
||||
if (Attr->getMask() & SanitizerKind::Address)
|
||||
IsBlacklisted = true;
|
||||
IsExcluded = true;
|
||||
reportGlobalToASan(GV, D.getLocation(), OS.str(), D.getType(), IsDynInit,
|
||||
IsBlacklisted);
|
||||
IsExcluded);
|
||||
}
|
||||
|
||||
void SanitizerMetadata::disableSanitizerForGlobal(llvm::GlobalVariable *GV) {
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
bool IsDynInit = false);
|
||||
void reportGlobalToASan(llvm::GlobalVariable *GV, SourceLocation Loc,
|
||||
StringRef Name, QualType Ty, bool IsDynInit = false,
|
||||
bool IsBlacklisted = false);
|
||||
bool IsExcluded = false);
|
||||
void disableSanitizerForGlobal(llvm::GlobalVariable *GV);
|
||||
void disableSanitizerForInstruction(llvm::Instruction *I);
|
||||
private:
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
LocationMetadata SourceLoc;
|
||||
StringRef Name;
|
||||
bool IsDynInit = false;
|
||||
bool IsBlacklisted = false;
|
||||
bool IsExcluded = false;
|
||||
|
||||
Entry() = default;
|
||||
};
|
||||
|
|
|
@ -1113,7 +1113,8 @@ bool CallAnalyzer::visitCastInst(CastInst &I) {
|
|||
}))
|
||||
return true;
|
||||
|
||||
// Disable SROA in the face of arbitrary casts we don't whitelist elsewhere.
|
||||
// Disable SROA in the face of arbitrary casts we don't explicitly list
|
||||
// elsewhere.
|
||||
disableSROA(I.getOperand(0));
|
||||
|
||||
// If this is a floating-point cast, and the target says this operation
|
||||
|
|
|
@ -153,7 +153,7 @@ ARCInstKind llvm::objcarc::GetFunctionClass(const Function *F) {
|
|||
}
|
||||
}
|
||||
|
||||
// A whitelist of intrinsics that we know do not use objc pointers or decrement
|
||||
// A list of intrinsics that we know do not use objc pointers or decrement
|
||||
// ref counts.
|
||||
static bool isInertIntrinsic(unsigned ID) {
|
||||
// TODO: Make this into a covered switch.
|
||||
|
@ -192,7 +192,7 @@ static bool isInertIntrinsic(unsigned ID) {
|
|||
}
|
||||
}
|
||||
|
||||
// A whitelist of intrinsics that we know do not use objc pointers or decrement
|
||||
// A list of intrinsics that we know do not use objc pointers or decrement
|
||||
// ref counts.
|
||||
static bool isUseOnlyIntrinsic(unsigned ID) {
|
||||
// We are conservative and even though intrinsics are unlikely to touch
|
||||
|
|
|
@ -195,10 +195,10 @@ CleanupPointerRootUsers(GlobalVariable *GV,
|
|||
function_ref<TargetLibraryInfo &(Function &)> GetTLI) {
|
||||
// A brief explanation of leak checkers. The goal is to find bugs where
|
||||
// pointers are forgotten, causing an accumulating growth in memory
|
||||
// usage over time. The common strategy for leak checkers is to whitelist the
|
||||
// memory pointed to by globals at exit. This is popular because it also
|
||||
// solves another problem where the main thread of a C++ program may shut down
|
||||
// before other threads that are still expecting to use those globals. To
|
||||
// usage over time. The common strategy for leak checkers is to explicitly
|
||||
// allow the memory pointed to by globals at exit. This is popular because it
|
||||
// also solves another problem where the main thread of a C++ program may shut
|
||||
// down before other threads that are still expecting to use those globals. To
|
||||
// handle that case, we expect the program may create a singleton and never
|
||||
// destroy it.
|
||||
|
||||
|
|
|
@ -1150,9 +1150,9 @@ GlobalsMetadata::GlobalsMetadata(Module &M) {
|
|||
E.Name = Name->getString();
|
||||
ConstantInt *IsDynInit = mdconst::extract<ConstantInt>(MDN->getOperand(3));
|
||||
E.IsDynInit |= IsDynInit->isOne();
|
||||
ConstantInt *IsBlacklisted =
|
||||
ConstantInt *IsExcluded =
|
||||
mdconst::extract<ConstantInt>(MDN->getOperand(4));
|
||||
E.IsBlacklisted |= IsBlacklisted->isOne();
|
||||
E.IsExcluded |= IsExcluded->isOne();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1814,7 +1814,7 @@ bool ModuleAddressSanitizer::shouldInstrumentGlobal(GlobalVariable *G) const {
|
|||
|
||||
// FIXME: Metadata should be attched directly to the global directly instead
|
||||
// of being added to llvm.asan.globals.
|
||||
if (GlobalsMD.get(G).IsBlacklisted) return false;
|
||||
if (GlobalsMD.get(G).IsExcluded) return false;
|
||||
if (!Ty->isSized()) return false;
|
||||
if (!G->hasInitializer()) return false;
|
||||
// Only instrument globals of default address spaces
|
||||
|
@ -2265,19 +2265,19 @@ bool ModuleAddressSanitizer::InstrumentGlobals(IRBuilder<> &IRB, Module &M,
|
|||
|
||||
// Build set of globals that are aliased by some GA, where
|
||||
// canInstrumentAliasedGlobal(GA) returns false.
|
||||
SmallPtrSet<const GlobalVariable *, 16> AliasedGlobalBlacklist;
|
||||
SmallPtrSet<const GlobalVariable *, 16> AliasedGlobalExclusions;
|
||||
if (CompileKernel) {
|
||||
for (auto &GA : M.aliases()) {
|
||||
if (const auto *GV = dyn_cast<GlobalVariable>(GA.getAliasee())) {
|
||||
if (!canInstrumentAliasedGlobal(GA))
|
||||
AliasedGlobalBlacklist.insert(GV);
|
||||
AliasedGlobalExclusions.insert(GV);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SmallVector<GlobalVariable *, 16> GlobalsToChange;
|
||||
for (auto &G : M.globals()) {
|
||||
if (!AliasedGlobalBlacklist.count(&G) && shouldInstrumentGlobal(&G))
|
||||
if (!AliasedGlobalExclusions.count(&G) && shouldInstrumentGlobal(&G))
|
||||
GlobalsToChange.push_back(&G);
|
||||
}
|
||||
|
||||
|
|
|
@ -1132,7 +1132,7 @@ static bool isIgnorableInst(const Instruction *I) {
|
|||
case Intrinsic::annotation:
|
||||
case Intrinsic::ptr_annotation:
|
||||
case Intrinsic::var_annotation:
|
||||
// TODO: the following intrinsics may also be whitelisted:
|
||||
// TODO: the following intrinsics may also be allowed:
|
||||
// lifetime_start, lifetime_end, invariant_start, invariant_end
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ bool NaryReassociatePass::runImpl(Function &F, AssumptionCache *AC_,
|
|||
return Changed;
|
||||
}
|
||||
|
||||
// Whitelist the instruction types NaryReassociate handles for now.
|
||||
// Explicitly list the instruction types NaryReassociate handles for now.
|
||||
static bool isPotentiallyNaryReassociable(Instruction *I) {
|
||||
switch (I->getOpcode()) {
|
||||
case Instruction::Add:
|
||||
|
|
|
@ -247,7 +247,7 @@ static unsigned ComputeSpeculationCost(const Instruction *I,
|
|||
return TTI.getUserCost(I, TargetTransformInfo::TCK_SizeAndLatency);
|
||||
|
||||
default:
|
||||
return UINT_MAX; // Disallow anything not whitelisted.
|
||||
return UINT_MAX; // Disallow anything not explicitly listed.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue