Skip to content

Commit a6edaeb

Browse files
authored
[DebugInfo][TailCallElim] Use ret DILocation for return value selects (#134825)
In TailRecursionElimination we may insert a select before the return to choose the return value if necessary; this select is effectively part of the return statement, and so should use its DILocation. Found using #107279.
1 parent 78c86b3 commit a6edaeb

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ bool TailRecursionEliminator::eliminateCall(CallInst *CI) {
725725
SelectInst *SI =
726726
SelectInst::Create(RetKnownPN, RetPN, Ret->getReturnValue(),
727727
"current.ret.tr", Ret->getIterator());
728+
SI->setDebugLoc(Ret->getDebugLoc());
728729
RetSelects.push_back(SI);
729730

730731
RetPN->addIncoming(SI, BB);
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
; RUN: opt < %s -passes=debugify,tailcallelim -S | FileCheck %s
22

3-
define void @foo() {
3+
define i32 @foo() {
44
entry:
55
; CHECK-LABEL: entry:
66
; CHECK: br label %tailrecurse{{$}}
77

8-
call void @foo() ;; line 1
9-
ret void
8+
%ret = call i32 @foo() ;; line 1
9+
ret i32 0 ;; line 2
1010

1111
; CHECK-LABEL: tailrecurse:
12-
; CHECK: br label %tailrecurse, !dbg ![[DbgLoc:[0-9]+]]
12+
; CHECK: select i1 {{.+}}, !dbg ![[DbgLoc2:[0-9]+]]
13+
; CHECK: br label %tailrecurse, !dbg ![[DbgLoc1:[0-9]+]]
1314
}
1415

1516
;; Make sure tailrecurse has the call instruction's DL
16-
; CHECK: ![[DbgLoc]] = !DILocation(line: 1
17+
; CHECK: ![[DbgLoc1]] = !DILocation(line: 1
18+
; CHECK: ![[DbgLoc2]] = !DILocation(line: 2

0 commit comments

Comments
 (0)