diff --git a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp index 519ff3221a3bc..34d39f3fe6dca 100644 --- a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp +++ b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp @@ -510,7 +510,9 @@ void TailRecursionEliminator::createTailRecurseLoopHeader(CallInst *CI) { NewEntry->takeName(HeaderBB); HeaderBB->setName("tailrecurse"); BranchInst *BI = BranchInst::Create(HeaderBB, NewEntry); - BI->setDebugLoc(CI->getDebugLoc()); + // If the new branch preserves the debug location of CI, it could result in + // misleading stepping, if CI is located in a conditional branch. + // So, here we don't give any debug location to BI. // Move all fixed sized allocas from HeaderBB to NewEntry. for (BasicBlock::iterator OEBI = HeaderBB->begin(), E = HeaderBB->end(), diff --git a/llvm/test/Transforms/TailCallElim/debugloc.ll b/llvm/test/Transforms/TailCallElim/debugloc.ll index 3abbd6552efce..49957695a421b 100644 --- a/llvm/test/Transforms/TailCallElim/debugloc.ll +++ b/llvm/test/Transforms/TailCallElim/debugloc.ll @@ -4,13 +4,13 @@ define void @foo() { entry: ; CHECK-LABEL: entry: -; CHECK: br label %tailrecurse, !dbg ![[DbgLoc:[0-9]+]] +; CHECK: br label %tailrecurse{{$}} call void @foo() ;; line 1 ret void ; CHECK-LABEL: tailrecurse: -; CHECK: br label %tailrecurse, !dbg ![[DbgLoc]] +; CHECK: br label %tailrecurse, !dbg ![[DbgLoc:[0-9]+]] } ;; Make sure tailrecurse has the call instruction's DL