Index: lib/Transforms/Scalar/TailRecursionElimination.cpp =================================================================== --- lib/Transforms/Scalar/TailRecursionElimination.cpp +++ lib/Transforms/Scalar/TailRecursionElimination.cpp @@ -566,7 +566,8 @@ BasicBlock *NewEntry = BasicBlock::Create(F->getContext(), "", F, OldEntry); NewEntry->takeName(OldEntry); OldEntry->setName("tailrecurse"); - BranchInst::Create(OldEntry, NewEntry); + BranchInst *BI = BranchInst::Create(OldEntry, NewEntry); + BI->setDebugLoc(CI->getDebugLoc()); // If this tail call is marked 'tail' and if there are any allocas in the // entry block, move them up to the new entry block. Index: test/Transforms/TailCallElim/debugloc.ll =================================================================== --- /dev/null +++ test/Transforms/TailCallElim/debugloc.ll @@ -0,0 +1,16 @@ +; RUN: opt < %s -debugify -tailcallelim -S | FileCheck %s + +define void @foo() { +entry: +; CHECK-LABEL: entry: +; CHECK: br label %tailrecurse, !dbg ![[DbgLoc:[0-9]+]] + + call void @foo() ;; line 1 + ret void + +; CHECK-LABEL: tailrecurse: +; CHECK: br label %tailrecurse, !dbg ![[DbgLoc]] +} + +;; Make sure tailrecurse has the call instruction's DL +; CHECK: ![[DbgLoc]] = !DILocation(line: 1