[LLVMdev] SwitchInst::addCase with BlockAddress

Eli Friedman eli.friedman at gmail.com
Sun Jul 31 23:13:12 PDT 2011

On Sun, Jul 31, 2011 at 7:36 AM, Carlo Alberto Ferraris
<cafxx at strayorange.com> wrote:
> I'm trying to figure out how to feed a blockaddress to a switch condition
> AND destination (basically emulating an indirectbr via a switch; I know it's
> not a good approach, I'm just experimenting).
> Suppose I have the following:
> SwitchInst *s = SwitchInst::Create(...);
> BasicBlock *bb = ...;
> PtrToIntInst k = new PtrToIntInst(BlockAddress::get(bb), <TYPE>, "", s);
> s->addCase(k, bb);
> ...
> is this reasonable? what should I put in place of <TYPE> (the type to cast
> to)?

You can't do that; switch cases are required to be constant integers,
and a blockaddress are not constant integers (at least not at

You can use an explicit comparison+branch, though.


More information about the llvm-dev mailing list