[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
This commit is contained in:
Vedant Kumar
2018-11-06 19:05:53 +00:00
parent c6613879ce
commit 09b7aa443d
2 changed files with 62 additions and 0 deletions

View File

@@ -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 <cassert>
#include <cstdint>
#include <iterator>
@@ -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<DbgInfoIntrinsic>(Inst))
Inst->eraseFromParent();
}
// Remove debug info intrinsics which refer to values in the new function
// from the old function.
SmallVector<DbgVariableIntrinsic *, 4> DbgUsers;
for (Instruction &I : BB)
findDbgUsers(DbgUsers, &I);
for (DbgVariableIntrinsic *DVI : DbgUsers)
DVI->eraseFromParent();
}
LLVM_DEBUG(if (verifyFunction(*newFunction))