Index: llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp =================================================================== --- llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -977,6 +977,7 @@ V = NewCB; // Insert the value at the old position RetVal = InsertValueInst::Create(RetVal, V, Ri, "oldret", InsertPt); + cast(RetVal)->setDebugLoc(CB.getDebugLoc()); } // Now, replace all uses of the old call instruction with the return // struct we built @@ -1046,6 +1047,7 @@ // extracted value. RetVal = EV; } + cast(RetVal)->setDebugLoc(RI->getDebugLoc()); } } // Replace the return instruction with one returning the new return Index: llvm/test/Transforms/DeadArgElim/insertval-dbg-info.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/DeadArgElim/insertval-dbg-info.ll @@ -0,0 +1,41 @@ +; RUN: opt -deadargelim -S < %s | FileCheck %s + +; CHECK: %[[invoke:.*]] = invoke i32 @fn1() +; CHECK: %[[oldret:.*]] = insertvalue { i32 } undef, i32 %[[invoke]], 0, !dbg + +define internal { i32 } @fn1() !dbg !4 { +entry: + unreachable +} + +define void @fn2() personality i32 (i32)* undef !dbg !8 { +entry: + %tmp2 = invoke { i32 } @fn1() + to label %bb3 unwind label %bb4, !dbg !15 +bb3: + %tmp3 = phi { i32 } [ %tmp2, %entry ], !dbg !15 + unreachable +bb4: + %tmp4 = landingpad { i8*, i32 } + cleanup, !dbg !15 + unreachable +} + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!12, !13} +!llvm.ident = !{!14} +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 11", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2) +!1 = !DIFile(filename: "test.cpp", directory: "/dir") +!2 = !{} +!4 = distinct !DISubprogram(name: "fn1", line: 4, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 4, file: !1, scope: !5, type: !6, retainedNodes: !2) +!5 = !DIFile(filename: "test.cpp", directory: "/dir") +!6 = !DISubroutineType(types: !7) +!7 = !{null} +!8 = distinct !DISubprogram(name: "fn2", line: 1, isLocal: true, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 1, file: !1, scope: !5, type: !9, retainedNodes: !2) +!9 = !DISubroutineType(types: !10) +!10 = !{null, !11, null} +!11 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!12 = !{i32 2, !"Dwarf Version", i32 4} +!13 = !{i32 2, !"Debug Info Version", i32 3} +!14 = !{!"clang version 11"} +!15 = !DILocation(line: 1, column: 19, scope: !8)