[LLVMdev] Catching C++ exceptions, cleaning up, rethrowing

Duncan Sands baldrick at free.fr
Mon Apr 9 09:14:00 PDT 2012


Hi,

>> What gets returned by the landingpad instruction (%0 here) is normally a structure. LLVM doesn't typically treat aggregates as first-class citizens.

registers of aggregate type are legal and work.  For example the dragonegg
frontend represents complex numbers as registers with type { float, float },
and it works fine.  However not many advanced optimizations are performed on
them.

  In particular, you shouldn't store the whole structure to memory like you do 
to %5.

It is fine to store them to memory and load them out again.  The dragonegg
frontend does this all the time for complex numbers.

  You can use 'extractvalue' to get the different elements of the structure. If 
you need to reconstitute the structure (for the 'resume' instruction), you can 
use the 'insertvalue' instruction. The code it produces is more verbose, but 
after optimizations, code-gen typically doesn't produce a lot of code for these 
sequences.

Indeed using extractvalue and insertvalue work fine too.  But it's not
obligatory.

Ciao, Duncan.

>
> I copied that bit of code from ExceptionDemo.cpp (lines 1270-1290):
>
>>    llvm::LandingPadInst *caughtResult =
>>      builder.CreateLandingPad(ourCaughtResultType,
>>                               personality,
>>                               numExceptionsToCatch,
>>                               "landingPad");
>>    // ...
>>
>>    builder.CreateStore(caughtResult, caughtResultStorage);
>
> Then on line 1255:
>
>>    builder.CreateResume(builder.CreateLoad(caughtResultStorage));
>
> Are you saying that code is wrong too?
>
> - Paul
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list