Search code examples
c++cllvmllvm-clangllvm-ir

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


I have a test.c file which has this function call:

functiontest(2,x);

I would like to delete this function call (with an llvm pass) and when I try to use removeFromParent() function like this:

calledFunction1->removeFromParent();

this causes LLVM to produce the following error:

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

LLVM ERROR: Broken function found, compilation aborted!

I also tried calling eraseFromParent() but this triggers an assert:

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

I would prefer to use removeFromParent()

Any ideas what's wrong ?


Solution

  • First of all, it would be really helpful if you could post a minimal code sample that demonstrates your problem. Otherwise, we can only guess. Some observations though:

    1. Why do you prefer removeFromParent? The call instruction has to be deleted too, that's what eraseFromParent does.
    2. Did you call replaceAllUsesWith before erasing/removing? Otherwise, uses stick around.
    3. Did you remove the function or the call instruction? This may explain the first error message.