[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:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user