[LLVMdev] Indirect branching to BasicBlock

dw dw.dev.mailing at gmail.com
Fri Nov 1 18:48:41 PDT 2013


Hello,

I'm currently writing a function pass for LLVM and face the following
problem. I want to store the address of a BasicBlock (or the label, as
LLVM refers to it) in a local variable (AllocaInst). Later on I intend
to indirectly branch to this address by "dereferencing" the variable.

Is this possible? I tried creating an instance of AllocaInst but I'm not
quite sure which type to use. Using block->getType() results in a
segmentation fault (Cannot allocate unsized type %myVar = alloca label).

Code might help:

AllocaInst *myVar = new AllocaInst(blockToStore.getType(), "myVar",
curBlock);
new StoreInst(&blockToStore, myVar);

I guess I should use an integer type to store the address but then LLVM
complains about type mismatch as I don not know how to cast the block's
label to an integer. I am not sure where to look this up, might be I
missed an important part in the docs.


Kind regards



More information about the llvm-dev mailing list