srividya-sundaram created this revision.
Herald added subscribers: luke, steakhal, frasercrmck, martong, luismarques,
apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult,
MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal,
simoncook, johnrusso, rbar, asb.
Herald added a reviewer: NoQ.
Herald added a project: All.
srividya-sundaram requested review of this revision.
Herald added subscribers: cfe-commits, wangpc, MaskRay.
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157129
Files:
clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/Analysis/FlowSensitive/RecordOps.cpp
clang/lib/Sema/SemaRISCVVectorLookup.cpp
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
clang/lib/StaticAnalyzer/Core/MemRegion.cpp
clang/lib/StaticAnalyzer/Core/ProgramState.cpp
clang/lib/StaticAnalyzer/Core/RegionStore.cpp
Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ 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<BlockDataRegion>(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<BlocksAttr>() || !VD->hasLocalStorage()) {
@@ -2844,7 +2844,7 @@
// All regions captured by a block are also live.
if (const BlockDataRegion *BR = dyn_cast<BlockDataRegion>(R)) {
- for (auto Var : BR->referenced_vars())
+ for (auto &Var : BR->referenced_vars())
AddToWorkList(Var.getCapturedRegion());
}
}
Index: clang/lib/StaticAnalyzer/Core/ProgramState.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ 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<BlockDataRegion>(R)) {
- for (auto Var : BDR->referenced_vars()) {
+ for (auto &Var : BDR->referenced_vars()) {
if (!scan(Var.getCapturedRegion()))
return false;
}
Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ 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<BlockInvocationContext>(LC)) {
const auto *BR = static_cast<const BlockDataRegion *>(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<VarRegion>(OrigR)) {
if (VR->getDecl() == VD)
Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ 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<unsigned>(0, -1), LE->getLambdaClass()->fields(),
LE->capture_inits())) {
SVal FieldLoc = State->getLValue(FieldForCapture, V);
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ 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();
Index: clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
@@ -57,7 +57,7 @@
ProgramStateRef state = C.getState();
auto *R = cast<BlockDataRegion>(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();
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ 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 =
Index: clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -138,7 +138,7 @@
StackAddrEscapeChecker::getCapturedStackRegions(const BlockDataRegion &B,
CheckerContext &C) {
SmallVector<const MemRegion *, 4> 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<StackSpaceRegion>(Region->getMemorySpace()))
Index: clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
@@ -163,7 +163,7 @@
ProgramStateRef State = C.getState();
SymbolVector LeakedStreams;
StreamMapTy TrackedStreams = State->get<StreamMap>();
- for (auto [Sym, StreamStatus] : TrackedStreams) {
+ for (auto &[Sym, StreamStatus] : TrackedStreams) {
bool IsSymDead = SymReaper.isDead(Sym);
// Collect leaked symbols.
Index: clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
+++ 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);
Index: clang/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp
+++ 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);
Index: clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
+++ 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)
Index: clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -942,7 +942,7 @@
ProgramStateRef NullabilityChecker::evalAssume(ProgramStateRef State, SVal Cond,
bool Assumption) const {
PropertyAccessesMapTy PropertyAccesses = State->get<PropertyAccessesMap>();
- 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<InvariantViolated>())
Out << Sep << NL;
- for (auto [Region, State] : B) {
+ for (auto &[Region, State] : B) {
Out << Region << " : ";
State.print(Out);
Out << NL;
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2818,7 +2818,7 @@
// Cleanup the Realloc Pairs Map.
ReallocPairsTy RP = state->get<ReallocPairs>();
- for (auto [Sym, ReallocPair] : RP) {
+ for (auto &[Sym, ReallocPair] : RP) {
if (SymReaper.isDead(Sym) || SymReaper.isDead(ReallocPair.ReallocatedSym)) {
state = state->remove<ReallocPairs>(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<ReallocPairs>();
- 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<RegionState>(Sym);
AllocationFamily Family = RefS->getAllocationFamily();
std::optional<MallocChecker::CheckKind> CheckKind =
Index: clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
+++ 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<AllocatedData>(Sym);
}
Index: clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
+++ 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<ObjCMethodDecl>(D)) {
- for (auto [Idx, FormalParam] : llvm::enumerate(OMD->parameters())) {
+ for (const auto &[Idx, FormalParam] :
+ llvm::enumerate(OMD->parameters())) {
if (isAnnotatedAsTakingLocalized(FormalParam)) {
argumentNumber = Idx;
break;
Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -2618,7 +2618,7 @@
return;
CStringLengthTy::Factory &F = state->get_context<CStringLength>();
- for (auto [Reg, Len] : Entries) {
+ for (auto &[Reg, Len] : Entries) {
if (SymbolRef Sym = Len.getAsSymbol()) {
if (SR.isDead(Sym))
Entries = F.remove(Entries, Reg);
Index: clang/lib/Sema/SemaRISCVVectorLookup.cpp
===================================================================
--- clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ 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<PrototypeDescriptor> PolicyPrototype =
RVVIntrinsic::computeBuiltinTypes(
BasicProtoSeq, /*IsMasked=*/true, Record.HasMaskedOffOperand,
Index: clang/lib/Analysis/FlowSensitive/RecordOps.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/RecordOps.cpp
+++ 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() ||
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===================================================================
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -3725,7 +3725,7 @@
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
OS << " BaseOffsets: [";
const CXXRecordDecl *Base = nullptr;
- for (auto I : CXXRD->bases()) {
+ for (auto &I : CXXRD->bases()) {
if (I.isVirtual())
continue;
if (Base)
Index: clang/lib/AST/Interp/ByteCodeEmitter.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ 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()};
Index: clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
===================================================================
--- clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
+++ 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";
}
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits