-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DebugInfo][Inlining] Propagate inlined resume
source loc to new br
#134826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…anch 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.
@llvm/pr-subscribers-llvm-transforms Author: Stephen Tozer (SLTozer) ChangesAs 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 #107279. Full diff: https://github.com/llvm/llvm-project/pull/134826.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 131fbe654c11c..1cdfcee739c8a 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..9ec965ac97609
--- /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: --tool ./build/bin/opt --version 5
+; RUN: ./build/bin/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]])
+;.
|
d799c41
to
433b8aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, seems like a straightforward replacement of instructions
…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.
…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.
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 #107279.