0
我想知道如何刪除LLVM中的一堆指令。 我嘗試以下(基於LLVM開發郵件列表後)刪除一堆llvm指令
// delete all instructions between [start,end)
void deleteAllInstructionsInRange(Instruction* startInst,Instruction* endInst)
{
BasicBlock::iterator it(startInst);
BasicBlock::iterator it_end(endInst);
it_end--;
Instruction* currentInst ;
while(it != it_end)
{
currentInst = &*it;
// this cannot be done at the end of the while loop.
// has to be incremented before "erasing" the instruction
++it;
if (!currentInst->use_empty())
{
currentInst->replaceAllUsesWith(UndefValue::get(currentInst->getType()));
}
currentInst->eraseFromParent();
}
}
一切正常,除了最後一次迭代。 任何人都明白爲什麼? (我嘗試過使用gdb,但是在最後一次迭代中給出了 中的段錯誤)