質問

I want to remove an UnreachableInst since a previous transformation has made it reachable. However, calling eraseFromParent() gives me a malformed BasicBlock since the UnreachableInst is the terminator of its BasicBlock. How do I fix the BasicBlock to terminate at the instruction previous to the UnreachableInst?

役に立ちましたか?

解決

Every basic block must end with a terminator. I think that the most straightforward way to remove the unreachable instruction, then, is to replace it with another terminator - for example, a branch into the next basic block, a return instruction, etc.

Take a look at llvm::ReplaceInstWithInst in BasicBlockUtils.h for a convenient way to replace one instruction with another.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top