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

Paul J. Lucas paul at lucasmail.org
Mon Apr 9 08:50:35 PDT 2012


On Apr 8, 2012, at 10:40 PM, Bill Wendling wrote:

> What gets returned by the landingpad instruction (%0 here) is normally a structure. LLVM doesn't typically treat aggregates as first-class citizens. In particular, you shouldn't store the whole structure to memory like you do to %5. 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.

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






More information about the llvm-dev mailing list