Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I admit I have little experience here, but have you seen the exception demo code example? It seems to contain exactly the kind of sequence you are hoping to find.</p> <p>Basically, you start by setting up the personality to behave as in C++:</p> <pre><code>llvm::Function *personality = module.getFunction("__gxx_personality_v0"); </code></pre> <p>You then create the landingpad with that personality and define its type:</p> <pre><code>llvm::LandingPadInst *caughtResult = builder.CreateLandingPad(ourCaughtResultType, personality, numExceptionsToCatch, "landingPad"); </code></pre> <p>Setting up the types to catch:</p> <pre><code>for (unsigned i = 0; i &lt; numExceptionsToCatch; ++i) { // Set up type infos to be caught caughtResult-&gt;addClause(module.getGlobalVariable( ourTypeInfoNames[exceptionTypesToCatch[i]])); } </code></pre> <p>And signalling it's a cleanup handler:</p> <pre><code>caughtResult-&gt;setCleanup(true); </code></pre> <p>This is it, I believe; now you can get the exception itself:</p> <pre><code>llvm::Value *unwindException = builder.CreateExtractValue(caughtResult, 0); </code></pre> <p>The <a href="https://llvm.org/viewvc/llvm-project/llvm/trunk/examples/ExceptionDemo/ExceptionDemo.cpp?view=markup&amp;sortby=file" rel="noreferrer">ExceptionDemo.cpp</a> file, from which these code segments are taken, contains a fuller sequence; specifically, it shows how to check the type root of the caught exception and branch into a specific block - your cleanup code - when it matches something:</p> <pre><code>llvm::Value *retTypeInfoIndex = builder.CreateExtractValue(caughtResult, 1); // FIXME: Redundant storage which, beyond utilizing value of // caughtResultStore for unwindException storage, may be alleviated // altogether with a block rearrangement builder.CreateStore(caughtResult, caughtResultStorage); builder.CreateStore(unwindException, exceptionStorage); builder.CreateStore(ourExceptionThrownState, exceptionCaughtFlag); // Retrieve exception_class member from thrown exception // (_Unwind_Exception instance). This member tells us whether or not // the exception is foreign. llvm::Value *unwindExceptionClass = builder.CreateLoad(builder.CreateStructGEP( builder.CreatePointerCast(unwindException, ourUnwindExceptionType-&gt;getPointerTo()), 0)); // Branch to the externalExceptionBlock if the exception is foreign or // to a catch router if not. Either way the finally block will be run. builder.CreateCondBr(builder.CreateICmpEQ(unwindExceptionClass, llvm::ConstantInt::get(builder.getInt64Ty(), ourBaseExceptionClass)), exceptionRouteBlock, externalExceptionBlock); </code></pre> <p>Finally, an additional example, along with explanations, is available <a href="http://blog.llvm.org/2011/11/llvm-30-exception-handling-redesign.html" rel="noreferrer">on the blog post that introduced the new exception handling mechanism</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload