[llvm] 9344b21 - [DebugInfo][Inlining] Propagate inlined `resume` source loc to new br (#134826)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 9 08:42:10 PDT 2025
Author: Stephen Tozer
Date: 2025-04-09T16:42:06+01:00
New Revision: 9344b2196cbc36cdc577314bbb2b889606ba6820
URL: https://github.com/llvm/llvm-project/commit/9344b2196cbc36cdc577314bbb2b889606ba6820
DIFF: https://github.com/llvm/llvm-project/commit/9344b2196cbc36cdc577314bbb2b889606ba6820.diff
LOG: [DebugInfo][Inlining] Propagate inlined `resume` source loc to new br (#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 https://github.com/llvm/llvm-project/pull/107279.
Added:
llvm/test/Transforms/Inline/X86/inline-landing-pad.ll
Modified:
llvm/lib/Transforms/Utils/InlineFunction.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 5beee1f681b81..4975fc81f0b31 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -241,7 +241,8 @@ void LandingPadInliningInfo::forwardResume(
BasicBlock *Dest = getInnerResumeDest();
BasicBlock *Src = RI->getParent();
- BranchInst::Create(Dest, Src);
+ auto *BI = BranchInst::Create(Dest, Src);
+ BI->setDebugLoc(RI->getDebugLoc());
// Update the PHIs in the destination. They were inserted in an order which
// makes this work.
diff --git a/llvm/test/Transforms/Inline/X86/inline-landing-pad.ll b/llvm/test/Transforms/Inline/X86/inline-landing-pad.ll
new file mode 100644
index 0000000000000..8422a4c1082a9
--- /dev/null
+++ b/llvm/test/Transforms/Inline/X86/inline-landing-pad.ll
@@ -0,0 +1,73 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -mtriple=x86_64-unknown-unknown -S -passes=inline | FileCheck %s
+;; Test that when we inline an invoked function, when we replace an inlined
+;; "resume" instruction with a branch to the landing pad block, we also transfer
+;; the resume's source location to the branch.
+
+define void @widget() personality ptr null !dbg !11 {
+; CHECK-LABEL: define void @widget(
+; CHECK-SAME: ) personality ptr null !dbg [[DBG4:![0-9]+]] {
+; CHECK-NEXT: [[BAZ_EXIT:.*]]:
+; CHECK-NEXT: br label %[[BB2_BODY:.*]], !dbg [[DBG7:![0-9]+]]
+; CHECK: [[BAZ_EXIT1:.*:]]
+; CHECK-NEXT: br label %[[BB1:.*]]
+; CHECK: [[BB1]]:
+; CHECK-NEXT: ret void
+; CHECK: [[BB2:.*]]:
+; CHECK-NEXT: [[LANDINGPAD:%.*]] = landingpad { ptr, i32 }
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: br label %[[BB2_BODY]]
+; CHECK: [[BB2_BODY]]:
+; CHECK-NEXT: [[EH_LPAD_BODY:%.*]] = phi { ptr, i32 } [ [[LANDINGPAD]], %[[BB2]] ], [ zeroinitializer, %[[BAZ_EXIT]] ]
+; CHECK-NEXT: br label %[[BB1]]
+;
+bb:
+ %invoke = invoke i32 @baz(ptr null, ptr null)
+ to label %bb1 unwind label %bb2, !dbg !4
+
+bb1: ; preds = %bb2, %bb
+ ret void
+
+bb2: ; preds = %bb
+ %landingpad = landingpad { ptr, i32 }
+ cleanup
+ br label %bb1
+}
+
+define i32 @baz(ptr %arg, ptr %arg1) personality ptr null !dbg !14 {
+; CHECK-LABEL: define i32 @baz(
+; CHECK-SAME: ptr [[ARG:%.*]], ptr [[ARG1:%.*]]) personality ptr null !dbg [[DBG8:![0-9]+]] {
+; CHECK-NEXT: [[BB:.*:]]
+; CHECK-NEXT: resume { ptr, i32 } zeroinitializer, !dbg [[DBG10:![0-9]+]]
+;
+bb:
+ resume { ptr, i32 } zeroinitializer, !dbg !15
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3}
+
+!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)
+!1 = !DIFile(filename: "inline-landing-pad.cpp", directory: "/tmp")
+!2 = !{}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !DILocation(line: 99, column: 17, scope: !11)
+!6 = !DIFile(filename: "inline-landing-pad.cpp", directory: "/tmp")
+!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)
+!12 = distinct !DISubroutineType(types: !13)
+!13 = !{null}
+!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)
+!15 = !DILocation(line: 9, column: 7, scope: !14)
+!16 = distinct !DISubroutineType(types: !13)
+;.
+; 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)
+; CHECK: [[META1]] = !DIFile(filename: "inline-landing-pad.cpp", directory: {{.*}})
+; CHECK: [[META2]] = !{}
+; 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]])
+; CHECK: [[META5]] = distinct !DISubroutineType(types: [[META6:![0-9]+]])
+; CHECK: [[META6]] = !{null}
+; CHECK: [[DBG7]] = !DILocation(line: 9, column: 7, scope: [[DBG8]], inlinedAt: [[META9:![0-9]+]])
+; 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]])
+; CHECK: [[META9]] = distinct !DILocation(line: 99, column: 17, scope: [[DBG4]])
+; CHECK: [[DBG10]] = !DILocation(line: 9, column: 7, scope: [[DBG8]])
+;.
More information about the llvm-commits
mailing list