From 4f55de6f81339a76c4eda767234952da1086dd52 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Mon, 4 Jun 2018 03:33:01 +0000 Subject: [PATCH] [Debugify] Add debug intrinsics before terminating musttail calls After r333856, opt -debugify would just stop emitting debug value intrinsics after encountering a musttail call. This wasn't sufficient to avoid verifier failures. Debug value intrinicss for all instructions preceding a musttail call must also be emitted before the musttail call. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333866 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/InstCombine/musttail-thunk.ll | 1 + tools/opt/Debugify.cpp | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/test/Transforms/InstCombine/musttail-thunk.ll b/test/Transforms/InstCombine/musttail-thunk.ll index 4038aa525a5..2e8e3a7b9c2 100644 --- a/test/Transforms/InstCombine/musttail-thunk.ll +++ b/test/Transforms/InstCombine/musttail-thunk.ll @@ -1,4 +1,5 @@ ; RUN: opt -instcombine -S < %s | FileCheck %s +; RUN: opt -debugify-each -instcombine -S < %s | FileCheck %s ; These are both direct calls, but make sure instcombine leaves the casts ; alone. diff --git a/tools/opt/Debugify.cpp b/tools/opt/Debugify.cpp index f26a95f2ba1..0a900a520ab 100644 --- a/tools/opt/Debugify.cpp +++ b/tools/opt/Debugify.cpp @@ -91,28 +91,32 @@ bool applyDebugifyMetadata(Module &M, if (BB.isEHPad()) continue; + // Debug values must be inserted before a musttail call (if one is + // present), or before the block terminator otherwise. + Instruction *LastInst = BB.getTerminatingMustTailCall(); + if (!LastInst) + LastInst = BB.getTerminator(); + // Attach debug values. - for (Instruction &I : BB) { + for (auto It = BB.begin(), End = LastInst->getIterator(); It != End; + ++It) { + Instruction &I = *It; + // Skip void-valued instructions. if (I.getType()->isVoidTy()) continue; - // Skip the terminator instruction and any just-inserted intrinsics. - if (isa(&I) || isa(&I)) + // Skip any just-inserted intrinsics. + if (isa(&I)) break; - // Don't insert instructions after a musttail call. - if (auto *Call = dyn_cast(&I)) - if (Call->isMustTailCall()) - break; - std::string Name = utostr(NextVar++); const DILocation *Loc = I.getDebugLoc().get(); auto LocalVar = DIB.createAutoVariable(SP, Name, File, Loc->getLine(), getCachedDIType(I.getType()), /*AlwaysPreserve=*/true); DIB.insertDbgValueIntrinsic(&I, LocalVar, DIB.createExpression(), Loc, - BB.getTerminator()); + LastInst); } } DIB.finalizeSubprogram(SP); -- 2.11.0