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); diff --git a/llvm/test/DebugInfo/X86/codegenprep-addrsink.ll b/llvm/test/DebugInfo/X86/codegenprep-addrsink.ll --- a/llvm/test/DebugInfo/X86/codegenprep-addrsink.ll +++ b/llvm/test/DebugInfo/X86/codegenprep-addrsink.ll @@ -33,9 +33,12 @@ ; CHECK-NEXT: %loaded = load i8, i8* %[[GEPVAR]] ; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* %[[GEPVAR]], ; CHECK-SAME: metadata ![[DIVAR]], +; CHECK-NEXT: call void @llvm.dbg.value(metadata !DIArgList(i8* %[[GEPVAR]], +; CHECK-SAME: i8* %[[GEPVAR]]), metadata ![[DIVAR]], call void @llvm.dbg.value(metadata i8 *%arith, metadata !12, metadata !DIExpression()), !dbg !14 %loaded = load i8, i8 *%arith call void @llvm.dbg.value(metadata i8 *%arith, metadata !12, metadata !DIExpression()), !dbg !14 + call void @llvm.dbg.value(metadata !DIArgList(i8 *%arith, i8 *%arith), metadata !12, metadata !DIExpression()), !dbg !14 ret i8 %loaded ret: