LLVM ERROR: Broken function found, compilation aborted! after removeFromParent()

LLVM ERROR: Broken function found, compilation aborted! after removeFromParent()

我有一个 test.c 文件,其中有这个函数调用:

functiontest(2,x);

我想删除这个函数调用(通过 llvm 传递),当我尝试像这样使用 removeFromParent() 函数时:

calledFunction1->removeFromParent();

这会导致 LLVM 产生以下错误:

Referencing function in another module!
call void @functiontest(i32 2, float %tmp15)

LLVM ERROR: Broken function found, compilation aborted!

我也试过调用 eraseFromParent() 但这会触发断言:

Assertion `use_empty() && "Uses remain when a value is destroyed!"' failed.

我更愿意使用 removeFromParent()

有什么问题吗?

首先,如果您能 post 一个演示您的问题的最小代码示例,那将非常有帮助。否则,我们只能猜测。不过有一些观察:

  1. 为什么你更喜欢removeFromParent?调用指令也必须删除,这就是 eraseFromParent 所做的。
  2. 你在erasing/removing之前给replaceAllUsesWith打电话了吗?否则,请坚持使用。
  3. 您是否删除了函数或调用指令?这可能解释了第一条错误消息。