diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index b35ccd3d6e78..3cdc75ca9869 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -1630,6 +1630,8 @@ void Verifier::visitDISubprogram(const DISubprogram &N) { if (auto *RawNode = N.getRawRetainedNodes()) { auto *Node = dyn_cast(RawNode); CheckDI(Node, "invalid retained nodes list", &N, RawNode); + + DenseMap Args; for (Metadata *Op : Node->operands()) { CheckDI(Op, "nullptr in retained nodes", &N, Node); @@ -1657,6 +1659,17 @@ void Verifier::visitDISubprogram(const DISubprogram &N) { "invalid retained nodes, retained node does not belong to subprogram", &N, Node, RetainedNode, RetainedNodeScope, RetainedNodeSP, RetainedNodeUnit); + + auto *DV = dyn_cast(RetainedNode); + if (!DV) + continue; + if (unsigned ArgNum = DV->getArg()) { + auto [ArgI, Inserted] = Args.insert({ArgNum, DV}); + CheckDI(Inserted || DV == ArgI->second, + "invalid retained nodes, more than one local variable with the " + "same argument index", + &N, N.getUnit(), Node, RetainedNode, Args[ArgNum]); + } } } CheckDI(!hasConflictingReferenceFlags(N.getFlags()), diff --git a/llvm/test/DebugInfo/MIR/X86/live-debug-values-reg-copy.mir b/llvm/test/DebugInfo/MIR/X86/live-debug-values-reg-copy.mir index 1f9cc7542fd9..abd50477f3d0 100644 --- a/llvm/test/DebugInfo/MIR/X86/live-debug-values-reg-copy.mir +++ b/llvm/test/DebugInfo/MIR/X86/live-debug-values-reg-copy.mir @@ -95,7 +95,7 @@ !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !11 = !{!12, !13} !12 = !DILocalVariable(name: "arg1", arg: 1, scope: !7, file: !1, line: 6, type: !10) - !13 = !DILocalVariable(name: "var1", arg: 1, scope: !7, file: !1, line: 6, type: !10) + !13 = !DILocalVariable(name: "var1", scope: !7, file: !1, line: 6, type: !10) !15 = !DILocation(line: 6, column: 13, scope: !7) !20 = !{!21, !21, i64 0} !21 = !{!"int", !22, i64 0}