Skip to content

Commit 343687a

Browse files
SLTozerIanWood1
authored andcommitted
[DebugInfo] Propagate source loc from invoke to replacement branch (llvm#137206)
An existing transformation replaces invoke instructions with a call to the invoked function and a branch to the destination; when this happens, we propagate the invoke's source location to the call but not to the branch. This patch updates this behaviour to propagate to the branch as well. Found using llvm#107279.
1 parent eb0c3be commit 343687a

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2964,7 +2964,11 @@ CallInst *llvm::changeToCall(InvokeInst *II, DomTreeUpdater *DTU) {
29642964

29652965
// Follow the call by a branch to the normal destination.
29662966
BasicBlock *NormalDestBB = II->getNormalDest();
2967-
BranchInst::Create(NormalDestBB, II->getIterator());
2967+
auto *BI = BranchInst::Create(NormalDestBB, II->getIterator());
2968+
// Although it takes place after the call itself, the new branch is still
2969+
// performing part of the control-flow functionality of the invoke, so we use
2970+
// II's DebugLoc.
2971+
BI->setDebugLoc(II->getDebugLoc());
29682972

29692973
// Update PHI nodes in the unwind destination
29702974
BasicBlock *BB = II->getParent();
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -p=simplifycfg -S | FileCheck %s
3+
4+
;; Test that when we replace the invoke of @baz with a call and branch to the
5+
;; invoke destination, we propagate the source location of the invoke to both
6+
;; the call and the branch.
7+
8+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
9+
target triple = "x86_64-unknown-linux-gnu"
10+
11+
define void @widget(i1 %arg) personality ptr null !dbg !5 {
12+
; CHECK-LABEL: define void @widget(
13+
; CHECK-SAME: i1 [[ARG:%.*]]) personality ptr null !dbg [[DBG5:![0-9]+]] {
14+
; CHECK-NEXT: [[BB:.*:]]
15+
; CHECK-NEXT: br i1 [[ARG]], label %[[BB2:.*]], label %[[BB1:.*]]
16+
; CHECK: [[BB1]]:
17+
; CHECK-NEXT: call void @baz(ptr null) #[[ATTR0:[0-9]+]], !dbg [[DBG8:![0-9]+]]
18+
; CHECK-NEXT: br label %[[BB2]], !dbg [[DBG8]]
19+
; CHECK: [[BB2]]:
20+
; CHECK-NEXT: ret void
21+
;
22+
bb:
23+
br i1 %arg, label %bb2, label %bb1
24+
25+
bb1: ; preds = %bb
26+
invoke void @baz(ptr null)
27+
to label %bb2 unwind label %bb3, !dbg !8
28+
29+
bb2: ; preds = %bb1, %bb
30+
ret void
31+
32+
bb3: ; preds = %bb1
33+
%landingpad = landingpad { ptr, i32 }
34+
cleanup
35+
store i1 false, ptr null, align 1
36+
ret void
37+
}
38+
39+
declare void @baz(ptr)
40+
41+
!llvm.dbg.cu = !{!0}
42+
!llvm.debugify = !{!2, !3}
43+
!llvm.module.flags = !{!4}
44+
45+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
46+
!1 = !DIFile(filename: "debugloc-invoke-to-call-br.ll", directory: "/")
47+
!2 = !{i32 6}
48+
!3 = !{i32 0}
49+
!4 = !{i32 2, !"Debug Info Version", i32 3}
50+
!5 = distinct !DISubprogram(name: "widget", linkageName: "widget", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
51+
!6 = !DISubroutineType(types: !7)
52+
!7 = !{}
53+
!8 = !DILocation(line: 1, column: 1, scope: !5)
54+
;.
55+
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C, file: [[META1:![0-9]+]], producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
56+
; CHECK: [[META1]] = !DIFile(filename: "debugloc-invoke-to-call-br.ll", directory: {{.*}})
57+
; CHECK: [[DBG5]] = distinct !DISubprogram(name: "widget", linkageName: "widget", scope: null, file: [[META1]], line: 1, type: [[META6:![0-9]+]], scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]])
58+
; CHECK: [[META6]] = !DISubroutineType(types: [[META7:![0-9]+]])
59+
; CHECK: [[META7]] = !{}
60+
; CHECK: [[DBG8]] = !DILocation(line: 1, column: 1, scope: [[DBG5]])
61+
;.

0 commit comments

Comments
 (0)