[clang] Use *{Map,Set}::contains (NFC)

This commit is contained in:
Kazu Hirata 2023-03-15 18:06:34 -07:00
parent 398af9b43b
commit 7eaa7b0553
19 changed files with 31 additions and 42 deletions

View File

@ -125,7 +125,7 @@ public:
///
/// `D` must not be assigned a storage location.
void setStorageLocation(const ValueDecl &D, StorageLocation &Loc) {
assert(DeclToLoc.find(&D) == DeclToLoc.end());
assert(!DeclToLoc.contains(&D));
DeclToLoc[&D] = &Loc;
}
@ -143,7 +143,7 @@ public:
/// `E` must not be assigned a storage location.
void setStorageLocation(const Expr &E, StorageLocation &Loc) {
const Expr &CanonE = ignoreCFGOmittedNodes(E);
assert(ExprToLoc.find(&CanonE) == ExprToLoc.end());
assert(!ExprToLoc.contains(&CanonE));
ExprToLoc[&CanonE] = &Loc;
}

View File

@ -251,8 +251,7 @@ const FileEntry *FileRemapper::getOriginalFile(StringRef filePath) {
I = ToFromMappings.find(file);
if (I != ToFromMappings.end()) {
file = I->second;
assert(FromToMappings.find(file) != FromToMappings.end() &&
"Original file not in mappings!");
assert(FromToMappings.contains(file) && "Original file not in mappings!");
}
return file;
}

View File

@ -1139,7 +1139,7 @@ unsigned ByteCodeExprGen<Emitter>::allocateLocalPrimitive(DeclTy &&Src,
if (const auto *VD =
dyn_cast_if_present<ValueDecl>(Src.dyn_cast<const Decl *>())) {
assert(!P.getGlobal(VD));
assert(Locals.find(VD) == Locals.end());
assert(!Locals.contains(VD));
}
// FIXME: There are cases where Src.is<Expr*>() is wrong, e.g.
@ -1161,7 +1161,7 @@ ByteCodeExprGen<Emitter>::allocateLocal(DeclTy &&Src, bool IsExtended) {
if (const auto *VD =
dyn_cast_if_present<ValueDecl>(Src.dyn_cast<const Decl *>())) {
assert(!P.getGlobal(VD));
assert(Locals.find(VD) == Locals.end());
assert(!Locals.contains(VD));
}
QualType Ty;

View File

@ -60,7 +60,7 @@ private:
void RegistryMaps::registerMatcher(
StringRef MatcherName, std::unique_ptr<MatcherDescriptor> Callback) {
assert(Constructors.find(MatcherName) == Constructors.end());
assert(!Constructors.contains(MatcherName));
Constructors[MatcherName] = std::move(Callback);
}

View File

@ -3387,8 +3387,7 @@ CFGBlock *CFGBuilder::VisitLabelStmt(LabelStmt *L) {
if (!LabelBlock) // This can happen when the body is empty, i.e.
LabelBlock = createBlock(); // scopes that only contains NullStmts.
assert(LabelMap.find(L->getDecl()) == LabelMap.end() &&
"label already in map");
assert(!LabelMap.contains(L->getDecl()) && "label already in map");
LabelMap[L->getDecl()] = JumpTarget(LabelBlock, ScopePos);
// Labels partition blocks, so this is the end of the basic block we were

View File

@ -316,10 +316,9 @@ BoolValue &DataflowAnalysisContext::substituteBoolValue(
BoolValue &DataflowAnalysisContext::buildAndSubstituteFlowCondition(
AtomicBoolValue &Token,
llvm::DenseMap<AtomicBoolValue *, BoolValue *> Substitutions) {
assert(
Substitutions.find(&getBoolLiteralValue(true)) == Substitutions.end() &&
Substitutions.find(&getBoolLiteralValue(false)) == Substitutions.end() &&
"Do not substitute true/false boolean literals");
assert(!Substitutions.contains(&getBoolLiteralValue(true)) &&
!Substitutions.contains(&getBoolLiteralValue(false)) &&
"Do not substitute true/false boolean literals");
llvm::DenseMap<BoolValue *, BoolValue *> SubstitutionsCache(
Substitutions.begin(), Substitutions.end());
return buildAndSubstituteFlowConditionWithCache(Token, SubstitutionsCache);

View File

@ -583,7 +583,7 @@ StorageLocation &Environment::createStorageLocation(const Expr &E) {
}
void Environment::setStorageLocation(const ValueDecl &D, StorageLocation &Loc) {
assert(DeclToLoc.find(&D) == DeclToLoc.end());
assert(!DeclToLoc.contains(&D));
DeclToLoc[&D] = &Loc;
}
@ -595,7 +595,7 @@ StorageLocation *Environment::getStorageLocation(const ValueDecl &D,
void Environment::setStorageLocation(const Expr &E, StorageLocation &Loc) {
const Expr &CanonE = ignoreCFGOmittedNodes(E);
assert(ExprToLoc.find(&CanonE) == ExprToLoc.end());
assert(!ExprToLoc.contains(&CanonE));
ExprToLoc[&CanonE] = &Loc;
}

View File

@ -447,7 +447,7 @@ public:
StringRef Name = StringRef(F).drop_front();
if (!llvm::is_contained(TargetIDFeatures, Name))
continue;
assert(OffloadArchFeatures.find(Name) == OffloadArchFeatures.end());
assert(!OffloadArchFeatures.contains(Name));
OffloadArchFeatures[Name] = IsOn;
}
return true;

View File

@ -1570,7 +1570,7 @@ namespace {
}
void setLocation(llvm::GlobalVariable *placeholder) {
assert(Locations.find(placeholder) == Locations.end() &&
assert(!Locations.contains(placeholder) &&
"already found location for placeholder!");
// Lazily fill in IndexValues with the values from Indices.

View File

@ -161,8 +161,7 @@ static const BlockExpr *getBlockExpr(const Expr *E) {
void CGOpenCLRuntime::recordBlockInfo(const BlockExpr *E,
llvm::Function *InvokeF,
llvm::Value *Block, llvm::Type *BlockTy) {
assert(EnqueuedBlockMap.find(E) == EnqueuedBlockMap.end() &&
"Block expression emitted twice");
assert(!EnqueuedBlockMap.contains(E) && "Block expression emitted twice");
assert(isa<llvm::Function>(InvokeF) && "Invalid invoke function");
assert(Block->getType()->isPointerTy() && "Invalid block literal type");
EnqueuedBlockMap[E].InvokeFunc = InvokeF;
@ -183,8 +182,7 @@ CGOpenCLRuntime::emitOpenCLEnqueuedBlock(CodeGenFunction &CGF, const Expr *E) {
// to get the block literal.
const BlockExpr *Block = getBlockExpr(E);
assert(EnqueuedBlockMap.find(Block) != EnqueuedBlockMap.end() &&
"Block expression not emitted");
assert(EnqueuedBlockMap.contains(Block) && "Block expression not emitted");
// Do not emit the block wrapper again if it has been emitted.
if (EnqueuedBlockMap[Block].KernelHandle) {

View File

@ -405,8 +405,7 @@ public:
if (!Offset || Offset + Size > FC.size())
return Error::success();
assert(BundlesInfo.find(Triple) == BundlesInfo.end() &&
"Triple is duplicated??");
assert(!BundlesInfo.contains(Triple) && "Triple is duplicated??");
BundlesInfo[Triple] = BinaryBundleInfo(Size, Offset);
}
// Set the iterator to where we will start to read.

View File

@ -162,7 +162,7 @@ private:
auto it = Jumps.find(Next);
if (it != Jumps.end()) {
Next = it->second;
assert(Jumps.find(Next) == Jumps.end());
assert(!Jumps.contains(Next));
}
return Next;
}

View File

@ -37,14 +37,12 @@ public:
AbbreviationMap() {}
void set(unsigned recordID, unsigned abbrevID) {
assert(Abbrevs.find(recordID) == Abbrevs.end()
&& "Abbreviation already set.");
assert(!Abbrevs.contains(recordID) && "Abbreviation already set.");
Abbrevs[recordID] = abbrevID;
}
unsigned get(unsigned recordID) {
assert(Abbrevs.find(recordID) != Abbrevs.end() &&
"Abbreviation not set.");
assert(Abbrevs.contains(recordID) && "Abbreviation not set.");
return Abbrevs[recordID];
}
};

View File

@ -4134,7 +4134,7 @@ void ASTReader::makeModuleVisible(Module *Mod,
auto HiddenNames = std::move(*Hidden);
HiddenNamesMap.erase(Hidden);
makeNamesVisible(HiddenNames.second, HiddenNames.first);
assert(HiddenNamesMap.find(Mod) == HiddenNamesMap.end() &&
assert(!HiddenNamesMap.contains(Mod) &&
"making names visible added hidden names");
}

View File

@ -1977,7 +1977,7 @@ void ASTDeclReader::MergeDefinitionData(
Reader.PendingDefinitions.erase(MergeDD.Definition);
MergeDD.Definition->setCompleteDefinition(false);
Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition);
assert(Reader.Lookups.find(MergeDD.Definition) == Reader.Lookups.end() &&
assert(!Reader.Lookups.contains(MergeDD.Definition) &&
"already loaded pending lookups for merged definition");
}

View File

@ -2805,7 +2805,7 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
case STMT_REF_PTR:
IsStmtReference = true;
assert(StmtEntries.find(Record[0]) != StmtEntries.end() &&
assert(StmtEntries.contains(Record[0]) &&
"No stmt was recorded for this offset reference!");
S = StmtEntries[Record.readInt()];
break;

View File

@ -5109,7 +5109,7 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
};
llvm::SmallVector<ModuleInfo, 64> Imports;
for (const auto *I : Context.local_imports()) {
assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end());
assert(SubmoduleIDs.contains(I->getImportedModule()));
Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()],
I->getImportedModule()));
}
@ -5457,7 +5457,7 @@ MacroID ASTWriter::getMacroID(MacroInfo *MI) {
if (!MI || MI->isBuiltinMacro())
return 0;
assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!");
assert(MacroIDs.contains(MI) && "Macro not emitted!");
return MacroIDs[MI];
}
@ -5632,7 +5632,7 @@ DeclID ASTWriter::getDeclID(const Decl *D) {
if (D->isFromASTFile())
return D->getGlobalID();
assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!");
assert(DeclIDs.contains(D) && "Declaration not emitted!");
return DeclIDs[D];
}
@ -6057,12 +6057,12 @@ void ASTWriter::SelectorRead(SelectorID ID, Selector S) {
void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID,
MacroDefinitionRecord *MD) {
assert(MacroDefinitions.find(MD) == MacroDefinitions.end());
assert(!MacroDefinitions.contains(MD));
MacroDefinitions[MD] = ID;
}
void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) {
assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end());
assert(!SubmoduleIDs.contains(Mod));
SubmoduleIDs[Mod] = ID;
}

View File

@ -2698,16 +2698,14 @@ void ASTStmtWriter::VisitOMPTargetParallelGenericLoopDirective(
//===----------------------------------------------------------------------===//
unsigned ASTWriter::RecordSwitchCaseID(SwitchCase *S) {
assert(SwitchCaseIDs.find(S) == SwitchCaseIDs.end() &&
"SwitchCase recorded twice");
assert(!SwitchCaseIDs.contains(S) && "SwitchCase recorded twice");
unsigned NextID = SwitchCaseIDs.size();
SwitchCaseIDs[S] = NextID;
return NextID;
}
unsigned ASTWriter::getSwitchCaseID(SwitchCase *S) {
assert(SwitchCaseIDs.find(S) != SwitchCaseIDs.end() &&
"SwitchCase hasn't been seen yet");
assert(SwitchCaseIDs.contains(S) && "SwitchCase hasn't been seen yet");
return SwitchCaseIDs[S];
}

View File

@ -2627,8 +2627,7 @@ BugPathInfo *BugPathGetter::getNextBugPath() {
const ExplodedNode *OrigN;
std::tie(CurrentBugPath.Report, OrigN) = ReportNodes.pop_back_val();
assert(PriorityMap.find(OrigN) != PriorityMap.end() &&
"error node not accessible from root");
assert(PriorityMap.contains(OrigN) && "error node not accessible from root");
// Create a new graph with a single path. This is the graph that will be
// returned to the caller.