shikai
shikai

Reputation: 11

LLVM IR jump to a basicblock within another function

I have generated an IR with my pass, inside a function in this IR, I would like to jump back to a basicblock of the caller function , inside caller function ext_callee function is invoked like this:

%4 = call i1 @ext_callee(i32 32, i32 %3, i32 -4, i8* blockaddress(@tobecalled, %5), i8* blockaddress(@tobecalled, %7)).

The last two parameters are the basicblock addresses I would like to jump to inside this ext_callee function. I tried to use indirectbr instruction with one of the blockaddress parameters but when I run the IR it prompts segment fault. I searched LLVM documents but didn't find how to jump to basicblocks of another function. Does anyone have a clue? Thanks very much!

Upvotes: 1

Views: 1445

Answers (1)

Anton Korobeynikov
Anton Korobeynikov

Reputation: 9324

You cannot do this.

Per http://llvm.org/docs/LangRef.html#i-indirectbr:

Control transfers to the block specified in the address argument. All possible destination blocks must be listed in the label list, otherwise this instruction has undefined behavior. This implies that jumps to labels defined in other functions have undefined behavior as well.

Upvotes: 1

Related Questions