[LLVMdev] cyclical use between caller and callee

Nick Lewycky nicholas at mxc.ca
Tue Mar 26 23:22:04 PDT 2013


charles quarra wrote:
> Hi,
>
> I have two functions in a module, X.foo, which is the callee, and
> Y.foo2, which calls X.foo.
>
> If i either try to run llvm::Function::eraseFromParent() on any one of
> the functions, i'll
> get this assertion error:
>
> F is used in instruction:
>    %"calling function" = call i32 @X.foo(i32 %read)
> F is used in instruction:
>    %"calling function" = call i32 @X.foo(i32 %read)
> While deleting: i32 (i32)* %X.foo
> Use still stuck around after Def is destroyed:  %"calling function" =
> call i32 @X.foo(i32 %read)
> mytests: Value.cpp:75: virtual llvm::Value::~Value(): Assertion
> `use_empty()&&  "Uses remain when a value is destroyed!"' failed.
>
> regardless of which one i call first.
>
> What is the appropiate way to delete a function from an existing module?

The common idiom to delete any Value* is:

V->replaceAllUsesWith(UndefValue::get(V->getType());
V->eraseFromParent();

Does that work for functions? You may need to make sure the 'undef' has 
a pointer to function type instead of the function type.

Nick



More information about the llvm-dev mailing list