diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -7994,7 +7994,9 @@ // Does this dbg.value refer to a sunk address calculation? bool AnyChange = false; - for (Value *Location : DVI.getValues()) { + SmallDenseSet LocationOps(DVI.location_ops().begin(), + DVI.location_ops().end()); + for (Value *Location : LocationOps) { WeakTrackingVH SunkAddrVH = SunkAddrs[Location]; Value *SunkAddr = SunkAddrVH.pointsToAliveValue() ? SunkAddrVH : nullptr; if (SunkAddr) { diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -1348,7 +1348,9 @@ for (auto &BB : F) { for (auto &Inst : BB) { if (auto *DVI = dyn_cast(&Inst)) { - for (Value *V : DVI->location_ops()) { + SmallDenseSet LocationOps(DVI->location_ops().begin(), + DVI->location_ops().end()); + for (Value *V : LocationOps) { if (auto *AI = dyn_cast_or_null(V)) { if (auto *NewAI = AllocaToPaddedAllocaMap.lookup(AI)) DVI->replaceVariableLocationOp(V, NewAI);