diff --git a/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h b/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h --- a/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h +++ b/clang/include/clang/Analysis/FlowSensitive/StorageLocation.h @@ -126,7 +126,7 @@ << " on StorageLocation " << this << " of type " << getType() << "\n"; llvm::dbgs() << "Existing children:\n"; - for ([[maybe_unused]] auto [Field, Loc] : Children) { + for ([[maybe_unused]] auto &[Field, Loc] : Children) { llvm::dbgs() << Field->getNameAsString() << "\n"; } } diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp --- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp +++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp @@ -61,7 +61,7 @@ MD->getParent()->getCaptureFields(LC, LTC); - for (auto Cap : LC) { + for (auto &Cap : LC) { unsigned Offset = R->getField(Cap.second)->Offset; this->LambdaCaptures[Cap.first] = { Offset, Cap.second->getType()->isReferenceType()}; diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp --- a/clang/lib/AST/RecordLayoutBuilder.cpp +++ b/clang/lib/AST/RecordLayoutBuilder.cpp @@ -3725,7 +3725,7 @@ if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) { OS << " BaseOffsets: ["; const CXXRecordDecl *Base = nullptr; - for (auto I : CXXRD->bases()) { + for (auto &I : CXXRD->bases()) { if (I.isVirtual()) continue; if (Base) diff --git a/clang/lib/Analysis/FlowSensitive/RecordOps.cpp b/clang/lib/Analysis/FlowSensitive/RecordOps.cpp --- a/clang/lib/Analysis/FlowSensitive/RecordOps.cpp +++ b/clang/lib/Analysis/FlowSensitive/RecordOps.cpp @@ -35,7 +35,7 @@ }); assert(compatibleTypes); - for (auto [Field, DstFieldLoc] : Dst.children()) { + for (auto &[Field, DstFieldLoc] : Dst.children()) { StorageLocation *SrcFieldLoc = Src.getChild(*Field); assert(Field->getType()->isReferenceType() || @@ -83,7 +83,7 @@ assert(Loc2.getType().getCanonicalType().getUnqualifiedType() == Loc1.getType().getCanonicalType().getUnqualifiedType()); - for (auto [Field, FieldLoc1] : Loc1.children()) { + for (auto &[Field, FieldLoc1] : Loc1.children()) { StorageLocation *FieldLoc2 = Loc2.getChild(*Field); assert(Field->getType()->isReferenceType() || diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp b/clang/lib/Sema/SemaRISCVVectorLookup.cpp --- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp +++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp @@ -302,7 +302,7 @@ if (Record.MaskedPolicyScheme == PolicyScheme::SchemeNone) continue; // Create masked policy intrinsic. - for (auto P : SupportedMaskedPolicies) { + for (auto &P : SupportedMaskedPolicies) { llvm::SmallVector PolicyPrototype = RVVIntrinsic::computeBuiltinTypes( BasicProtoSeq, /*IsMasked=*/true, Record.HasMaskedOffOperand, diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -2618,7 +2618,7 @@ return; CStringLengthTy::Factory &F = state->get_context(); - for (auto [Reg, Len] : Entries) { + for (auto &[Reg, Len] : Entries) { if (SymbolRef Sym = Len.getAsSymbol()) { if (SR.isDead(Sym)) Entries = F.remove(Entries, Reg); diff --git a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp @@ -848,7 +848,8 @@ if (argumentNumber < 0) { // There was no match in UIMethods if (const Decl *D = msg.getDecl()) { if (const ObjCMethodDecl *OMD = dyn_cast_or_null(D)) { - for (auto [Idx, FormalParam] : llvm::enumerate(OMD->parameters())) { + for (const auto &[Idx, FormalParam] : + llvm::enumerate(OMD->parameters())) { if (isAnnotatedAsTakingLocalized(FormalParam)) { argumentNumber = Idx; break; diff --git a/clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp @@ -531,7 +531,7 @@ } if (ReturnSymbol) - for (auto [Sym, AllocState] : AMap) { + for (auto &[Sym, AllocState] : AMap) { if (ReturnSymbol == AllocState.Region) State = State->remove(Sym); } diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -2818,7 +2818,7 @@ // Cleanup the Realloc Pairs Map. ReallocPairsTy RP = state->get(); - for (auto [Sym, ReallocPair] : RP) { + for (auto &[Sym, ReallocPair] : RP) { if (SymReaper.isDead(Sym) || SymReaper.isDead(ReallocPair.ReallocatedSym)) { state = state->remove(Sym); } @@ -3078,7 +3078,7 @@ // Realloc returns 0 when reallocation fails, which means that we should // restore the state of the pointer being reallocated. ReallocPairsTy RP = state->get(); - for (auto [Sym, ReallocPair] : RP) { + for (auto &[Sym, ReallocPair] : RP) { // If the symbol is assumed to be NULL, remove it from consideration. ConstraintManager &CMgr = state->getConstraintManager(); ConditionTruthVal AllocFailed = CMgr.isNull(state, Sym); @@ -3555,7 +3555,7 @@ if (!RS.isEmpty()) { Out << Sep << "MallocChecker :" << NL; - for (auto [Sym, Data] : RS) { + for (auto &[Sym, Data] : RS) { const RefState *RefS = State->get(Sym); AllocationFamily Family = RefS->getAllocationFamily(); std::optional CheckKind = diff --git a/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp @@ -942,7 +942,7 @@ ProgramStateRef NullabilityChecker::evalAssume(ProgramStateRef State, SVal Cond, bool Assumption) const { PropertyAccessesMapTy PropertyAccesses = State->get(); - for (auto [PropKey, PropVal] : PropertyAccesses) { + for (auto &[PropKey, PropVal] : PropertyAccesses) { if (!PropVal.isConstrainedNonnull) { ConditionTruthVal IsNonNull = State->isNonNull(PropVal.Value); if (IsNonNull.isConstrainedTrue()) { @@ -1370,7 +1370,7 @@ if (!State->get()) Out << Sep << NL; - for (auto [Region, State] : B) { + for (auto &[Region, State] : B) { Out << Region << " : "; State.print(Out); Out << NL; diff --git a/clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp @@ -362,7 +362,7 @@ } Out << NL; - for (auto [Sym, Flag] : FlagMap) { + for (auto &[Sym, Flag] : FlagMap) { Out << Sym << " : "; if (Flag == SelfFlag_None) diff --git a/clang/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp @@ -151,7 +151,7 @@ Scan(M, D->getDeclContext(), SM.getFileID(D->getLocation()), SM); // Find ivars that are unused. - for (auto [Ivar, State] : M) + for (auto &[Ivar, State] : M) if (State == Unused) { std::string sbuf; llvm::raw_string_ostream os(sbuf); diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp @@ -166,7 +166,7 @@ const LocationContext *LC = C.getLocationContext(); MemRegionManager &MemMgr = C.getSValBuilder().getRegionManager(); - for (auto Var : ReferencedVars) { + for (auto &Var : ReferencedVars) { const VarRegion *VR = Var.getCapturedRegion(); if (VR->getSuperRegion() == R) { VR = MemMgr.getVarRegion(VR->getDecl(), LC); diff --git a/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp @@ -163,7 +163,7 @@ ProgramStateRef State = C.getState(); SymbolVector LeakedStreams; StreamMapTy TrackedStreams = State->get(); - for (auto [Sym, StreamStatus] : TrackedStreams) { + for (auto &[Sym, StreamStatus] : TrackedStreams) { bool IsSymDead = SymReaper.isDead(Sym); // Collect leaked symbols. diff --git a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp @@ -138,7 +138,7 @@ StackAddrEscapeChecker::getCapturedStackRegions(const BlockDataRegion &B, CheckerContext &C) { SmallVector Regions; - for (auto Var : B.referenced_vars()) { + for (auto &Var : B.referenced_vars()) { SVal Val = C.getState()->getSVal(Var.getCapturedRegion()); const MemRegion *Region = Val.getAsRegion(); if (Region && isa(Region->getMemorySpace())) diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp @@ -991,7 +991,7 @@ if (Ranges.empty()) return; - for (auto [Start, End] : getRanges()) { + for (auto &[Start, End] : getRanges()) { const llvm::APSInt &Min = BVF.getValue(Start, ArgT); const llvm::APSInt &Max = BVF.getValue(End, ArgT); assert(Min <= Max); @@ -1501,7 +1501,7 @@ } // Check the argument types. - for (auto [Idx, ArgTy] : llvm::enumerate(ArgTys)) { + for (const auto &[Idx, ArgTy] : llvm::enumerate(ArgTys)) { if (isIrrelevant(ArgTy)) continue; QualType FDArgTy = diff --git a/clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp @@ -57,7 +57,7 @@ ProgramStateRef state = C.getState(); auto *R = cast(C.getSVal(BE).getAsRegion()); - for (auto Var : R->referenced_vars()) { + for (auto &Var : R->referenced_vars()) { // This VarRegion is the region associated with the block; we need // the one associated with the encompassing context. const VarRegion *VR = Var.getCapturedRegion(); diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp --- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp @@ -211,7 +211,7 @@ auto ReferencedVars = BDR->referenced_vars(); auto CI = BD->capture_begin(); auto CE = BD->capture_end(); - for (auto Var : ReferencedVars) { + for (auto &Var : ReferencedVars) { const VarRegion *capturedR = Var.getCapturedRegion(); const TypedValueRegion *originalR = Var.getOriginalRegion(); diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp @@ -1193,7 +1193,7 @@ // If we created a new MemRegion for the lambda, we should explicitly bind // the captures. - for (auto const [Idx, FieldForCapture, InitExpr] : + for (auto const &[Idx, FieldForCapture, InitExpr] : llvm::zip(llvm::seq(0, -1), LE->getLambdaClass()->fields(), LE->capture_inits())) { SVal FieldLoc = State->getLValue(FieldForCapture, V); diff --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp --- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp +++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp @@ -492,7 +492,7 @@ void BlockDataRegion::dumpToStream(raw_ostream &os) const { os << "block_data{" << BC; os << "; "; - for (auto Var : referenced_vars()) + for (auto &Var : referenced_vars()) os << "(" << Var.getCapturedRegion() << "<-" << Var.getOriginalRegion() << ") "; os << '}'; @@ -966,7 +966,7 @@ if (const auto *BC = dyn_cast(LC)) { const auto *BR = static_cast(BC->getData()); // FIXME: This can be made more efficient. - for (auto Var : BR->referenced_vars()) { + for (auto &Var : BR->referenced_vars()) { const TypedValueRegion *OrigR = Var.getOriginalRegion(); if (const auto *VR = dyn_cast(OrigR)) { if (VR->getDecl() == VD) diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp --- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp +++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp @@ -627,7 +627,7 @@ // Regions captured by a block are also implicitly reachable. if (const BlockDataRegion *BDR = dyn_cast(R)) { - for (auto Var : BDR->referenced_vars()) { + for (auto &Var : BDR->referenced_vars()) { if (!scan(Var.getCapturedRegion())) return false; } diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp --- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp +++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp @@ -1089,7 +1089,7 @@ // BlockDataRegion? If so, invalidate captured variables that are passed // by reference. if (const BlockDataRegion *BR = dyn_cast(baseR)) { - for (auto Var : BR->referenced_vars()) { + for (auto &Var : BR->referenced_vars()) { const VarRegion *VR = Var.getCapturedRegion(); const VarDecl *VD = VR->getDecl(); if (VD->hasAttr() || !VD->hasLocalStorage()) { @@ -2844,7 +2844,7 @@ // All regions captured by a block are also live. if (const BlockDataRegion *BR = dyn_cast(R)) { - for (auto Var : BR->referenced_vars()) + for (auto &Var : BR->referenced_vars()) AddToWorkList(Var.getCapturedRegion()); } }