[LLVMdev] Steps to addDestination

Tim Northover t.p.northover at gmail.com
Tue Jul 23 07:38:20 PDT 2013


Hi Rasha,

> I need to addDestination to some basic blocks

Just to make sure there's no confusion here: you really are trying to
create code like:

define i32 @foo(i1 %tst) {
  %Address = select i1 %tst, i8* blockaddress(@foo, %true), i8*
blockaddress(@foo, %false)
  indirectbr i8* %Address, [label %true, label %false] ; This is what
you're creating
true:
  ret i32 42
false:
  ret i32 0
}

and not:

define i32 @bar(i1 %tst) {
  br i1 %tst, label %true, label %false ; You're not trying to create this
true:
  ret i32 42
false:
  ret i32 0
}

If that's incorrect, you're going about it entirely the wrong way. We
can help with either, but it's best not to go too far on a
misunderstanding.

>  Value* Address;
>   IndirectBrInst *IBI = IndirectBrInst::Create(Address, Result.size(),i->getTerminator() );
>
> IBI->addDestination(i);

The problem seems to be that "Address" is uninitialised but it needs
to be set to some valid pointer value before creating your IndirectBr.
To replicate my first example it would be set to the "select"
instruction, for example; whatever produces your testination
blockaddress.

Cheers.

Tim.



More information about the llvm-dev mailing list