From 09b7aa443d6b40b0bc4dc7d43f61dcf1d420fd3b Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Tue, 6 Nov 2018 19:05:53 +0000 Subject: [CodeExtractor] Erase use-without-def debug intrinsics in parent func When CodeExtractor moves instructions to a new function, debug intrinsics referring to those instructions within the parent function become invalid. This results in the same verifier failure which motivated r344545, about function-local metadata being used in the wrong function. llvm-svn: 346255 --- llvm/lib/Transforms/Utils/CodeExtractor.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'llvm/lib/Transforms/Utils/CodeExtractor.cpp') diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index 462dc588cd5..4e48910b03c 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -57,6 +57,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" +#include "llvm/Transforms/Utils/Local.h" #include #include #include @@ -1305,12 +1306,20 @@ Function *CodeExtractor::extractCodeRegion() { // for the new function. for (BasicBlock &BB : *newFunction) { auto BlockIt = BB.begin(); + // Remove debug info intrinsics from the new function. while (BlockIt != BB.end()) { Instruction *Inst = &*BlockIt; ++BlockIt; if (isa(Inst)) Inst->eraseFromParent(); } + // Remove debug info intrinsics which refer to values in the new function + // from the old function. + SmallVector DbgUsers; + for (Instruction &I : BB) + findDbgUsers(DbgUsers, &I); + for (DbgVariableIntrinsic *DVI : DbgUsers) + DVI->eraseFromParent(); } LLVM_DEBUG(if (verifyFunction(*newFunction)) -- cgit v1.2.3