Skip to content

Commit 93505f8

Browse files
authored
[DebugInfo][InstCombine] Propagate DILocation when noop-ing invoke (#134678)
In InstCombine we may decide that an alloc is removable, and the alloc fn is called by an InvokeInst, we replace that InvokeInst with a invoke of a noop intrinsic; this patch has us also copy the original invoke's DILocation to the new noop invoke. Found using #107279.
1 parent e1fc118 commit 93505f8

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,8 +3406,9 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
34063406
// Replace invoke with a NOP intrinsic to maintain the original CFG
34073407
Module *M = II->getModule();
34083408
Function *F = Intrinsic::getOrInsertDeclaration(M, Intrinsic::donothing);
3409-
InvokeInst::Create(F, II->getNormalDest(), II->getUnwindDest(), {}, "",
3410-
II->getParent());
3409+
auto *NewII = InvokeInst::Create(
3410+
F, II->getNormalDest(), II->getUnwindDest(), {}, "", II->getParent());
3411+
NewII->setDebugLoc(II->getDebugLoc());
34113412
}
34123413

34133414
// Remove debug intrinsics which describe the value contained within the
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -passes=instcombine -S %s -o - | FileCheck %s
3+
4+
define void @foo() personality ptr null !dbg !4 {
5+
; CHECK-LABEL: define void @foo(
6+
; CHECK-SAME: ) personality ptr null !dbg [[DBG3:![0-9]+]] {
7+
; CHECK-NEXT: [[ENTRY:.*:]]
8+
; CHECK-NEXT: invoke void @llvm.donothing()
9+
; CHECK-NEXT: to label %[[COMMON_RET:.*]] unwind label %[[LPAD159:.*]], !dbg [[DBG7:![0-9]+]]
10+
; CHECK: [[COMMON_RET]]:
11+
; CHECK-NEXT: ret void
12+
; CHECK: [[LPAD159]]:
13+
; CHECK-NEXT: [[TMP0:%.*]] = landingpad { ptr, i32 }
14+
; CHECK-NEXT: cleanup
15+
; CHECK-NEXT: br label %[[COMMON_RET]]
16+
;
17+
entry:
18+
%call.i.i895904 = invoke ptr @_Znam(i64 0)
19+
to label %common.ret unwind label %lpad159, !dbg !9
20+
21+
common.ret: ; preds = %lpad159, %entry
22+
ret void
23+
24+
lpad159: ; preds = %entry
25+
%0 = landingpad { ptr, i32 }
26+
cleanup
27+
br label %common.ret
28+
}
29+
30+
declare ptr @_Znam(i64)
31+
32+
!llvm.dbg.cu = !{!0}
33+
!llvm.module.flags = !{!3}
34+
35+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0git")
36+
!1 = !DIFile(filename: "ArchiveCommandLine.cpp", directory: "/tmp")
37+
!2 = !{}
38+
!3 = !{i32 2, !"Debug Info Version", i32 3}
39+
!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 13, type: !6, scopeLine: 13, unit: !0, retainedNodes: !2)
40+
!6 = distinct !DISubroutineType(types: !7)
41+
!7 = !{null}
42+
!9 = !DILocation(line: 14, column: 20, scope: !4)
43+
;.
44+
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
45+
; CHECK: [[META1]] = !DIFile(filename: "ArchiveCommandLine.cpp", directory: {{.*}})
46+
; CHECK: [[DBG3]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 13, type: [[META4:![0-9]+]], scopeLine: 13, spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META6:![0-9]+]])
47+
; CHECK: [[META4]] = distinct !DISubroutineType(types: [[META5:![0-9]+]])
48+
; CHECK: [[META5]] = !{null}
49+
; CHECK: [[META6]] = !{}
50+
; CHECK: [[DBG7]] = !DILocation(line: 14, column: 20, scope: [[DBG3]])
51+
;.

0 commit comments

Comments
 (0)