[LLVMdev] Indirect branching to BasicBlock
Henrique Santos
henrique.nazare.santos at gmail.com
Sat Nov 2 04:17:36 PDT 2013
Check out the generated code for:
--
#include <stdio.h>
int main(int argc, char **argv) {
static void *array[] = { &&foo, &&bar };
goto *array[argc % 2];
foo:
puts("foo");
return 0;
bar:
puts("bar");
return 0;
}
--
Also, take a look at the class BlockAddress in llvm/IR/Constants.h.
I think those might help you out.
H.
On Fri, Nov 1, 2013 at 11:48 PM, dw <dw.dev.mailing at gmail.com> wrote:
> 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
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131102/fe5c6eb2/attachment.html>
More information about the llvm-dev
mailing list