Skip to content

Commit 2d6171a

Browse files
SLTozervar-const
authored andcommitted
[DebugInfo][Inlining] Propagate inlined resume source loc to new br (llvm#134826)
As part of inlining an invoke instruction, we may replace an inlined resume instruction with a simple branch to the landing pad block. When this happens, we should also propagate the resume's DILocation to this branch, which this patch enables. Found using llvm#107279.
1 parent 5856122 commit 2d6171a

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

llvm/lib/Transforms/Utils/InlineFunction.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ void LandingPadInliningInfo::forwardResume(
241241
BasicBlock *Dest = getInnerResumeDest();
242242
BasicBlock *Src = RI->getParent();
243243

244-
BranchInst::Create(Dest, Src);
244+
auto *BI = BranchInst::Create(Dest, Src);
245+
BI->setDebugLoc(RI->getDebugLoc());
245246

246247
// Update the PHIs in the destination. They were inserted in an order which
247248
// makes this work.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -mtriple=x86_64-unknown-unknown -S -passes=inline | FileCheck %s
3+
;; Test that when we inline an invoked function, when we replace an inlined
4+
;; "resume" instruction with a branch to the landing pad block, we also transfer
5+
;; the resume's source location to the branch.
6+
7+
define void @widget() personality ptr null !dbg !11 {
8+
; CHECK-LABEL: define void @widget(
9+
; CHECK-SAME: ) personality ptr null !dbg [[DBG4:![0-9]+]] {
10+
; CHECK-NEXT: [[BAZ_EXIT:.*]]:
11+
; CHECK-NEXT: br label %[[BB2_BODY:.*]], !dbg [[DBG7:![0-9]+]]
12+
; CHECK: [[BAZ_EXIT1:.*:]]
13+
; CHECK-NEXT: br label %[[BB1:.*]]
14+
; CHECK: [[BB1]]:
15+
; CHECK-NEXT: ret void
16+
; CHECK: [[BB2:.*]]:
17+
; CHECK-NEXT: [[LANDINGPAD:%.*]] = landingpad { ptr, i32 }
18+
; CHECK-NEXT: cleanup
19+
; CHECK-NEXT: br label %[[BB2_BODY]]
20+
; CHECK: [[BB2_BODY]]:
21+
; CHECK-NEXT: [[EH_LPAD_BODY:%.*]] = phi { ptr, i32 } [ [[LANDINGPAD]], %[[BB2]] ], [ zeroinitializer, %[[BAZ_EXIT]] ]
22+
; CHECK-NEXT: br label %[[BB1]]
23+
;
24+
bb:
25+
%invoke = invoke i32 @baz(ptr null, ptr null)
26+
to label %bb1 unwind label %bb2, !dbg !4
27+
28+
bb1: ; preds = %bb2, %bb
29+
ret void
30+
31+
bb2: ; preds = %bb
32+
%landingpad = landingpad { ptr, i32 }
33+
cleanup
34+
br label %bb1
35+
}
36+
37+
define i32 @baz(ptr %arg, ptr %arg1) personality ptr null !dbg !14 {
38+
; CHECK-LABEL: define i32 @baz(
39+
; CHECK-SAME: ptr [[ARG:%.*]], ptr [[ARG1:%.*]]) personality ptr null !dbg [[DBG8:![0-9]+]] {
40+
; CHECK-NEXT: [[BB:.*:]]
41+
; CHECK-NEXT: resume { ptr, i32 } zeroinitializer, !dbg [[DBG10:![0-9]+]]
42+
;
43+
bb:
44+
resume { ptr, i32 } zeroinitializer, !dbg !15
45+
}
46+
47+
!llvm.dbg.cu = !{!0}
48+
!llvm.module.flags = !{!3}
49+
50+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0git", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, globals: !2, imports: !2, splitDebugInlining: false, nameTableKind: None)
51+
!1 = !DIFile(filename: "inline-landing-pad.cpp", directory: "/tmp")
52+
!2 = !{}
53+
!3 = !{i32 2, !"Debug Info Version", i32 3}
54+
!4 = !DILocation(line: 99, column: 17, scope: !11)
55+
!6 = !DIFile(filename: "inline-landing-pad.cpp", directory: "/tmp")
56+
!11 = distinct !DISubprogram(name: "widget", linkageName: "widget", scope: !6, file: !6, line: 87, type: !12, scopeLine: 88, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
57+
!12 = distinct !DISubroutineType(types: !13)
58+
!13 = !{null}
59+
!14 = distinct !DISubprogram(name: "baz", linkageName: "baz", scope: !6, file: !6, line: 7, type: !12, scopeLine: 8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
60+
!15 = !DILocation(line: 9, column: 7, scope: !14)
61+
!16 = distinct !DISubroutineType(types: !13)
62+
;.
63+
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: [[META2:![0-9]+]], globals: [[META2]], imports: [[META2]], splitDebugInlining: false, nameTableKind: None)
64+
; CHECK: [[META1]] = !DIFile(filename: "inline-landing-pad.cpp", directory: {{.*}})
65+
; CHECK: [[META2]] = !{}
66+
; CHECK: [[DBG4]] = distinct !DISubprogram(name: "widget", linkageName: "widget", scope: [[META1]], file: [[META1]], line: 87, type: [[META5:![0-9]+]], scopeLine: 88, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META2]])
67+
; CHECK: [[META5]] = distinct !DISubroutineType(types: [[META6:![0-9]+]])
68+
; CHECK: [[META6]] = !{null}
69+
; CHECK: [[DBG7]] = !DILocation(line: 9, column: 7, scope: [[DBG8]], inlinedAt: [[META9:![0-9]+]])
70+
; CHECK: [[DBG8]] = distinct !DISubprogram(name: "baz", linkageName: "baz", scope: [[META1]], file: [[META1]], line: 7, type: [[META5]], scopeLine: 8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META2]])
71+
; CHECK: [[META9]] = distinct !DILocation(line: 99, column: 17, scope: [[DBG4]])
72+
; CHECK: [[DBG10]] = !DILocation(line: 9, column: 7, scope: [[DBG8]])
73+
;.

0 commit comments

Comments
 (0)