Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8786877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:44:46+00:00 2026-06-13T21:44:46+00:00

I have created a basic function Foo1 that calls another one Bar2 through invoke.

  • 0

I have created a basic function Foo1 that calls another one Bar2 through invoke. The first instruction in the unwind cleanup basic block must be the landing pad:

void bar2()
{ 
  throw;
}
llvm::Function* Bar2Fn = llvm::Function::Create( voidSig , &bar2);
engine->addGlobalMapping( Bar2Fn, (void*)&bar2 );
llvm::InvokeInst* inv = builder.CreateInvoke( Bar2Fn , continueBlock, unwindBlock, llvmArgValues , "invoke");
builder.CreateBr(continueBlock);
builder.SetInsertPoint(unwindBlock);
llvm::LandingPadInst* landPadInst = builder.CreateLandingPad(...);
//add some cleanup code? where??

I have honestly no idea what i need to put between the parameters of CreateLandingPad in order to get a basic landing pad that invokes a custom clean up code for the current Foo1 stack objects. Bar2 might throw by calling c++ functions that themselves throw (or rethrow an existing exception)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:44:47+00:00Added an answer on June 13, 2026 at 9:44 pm

    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.

    Basically, you start by setting up the personality to behave as in C++:

    llvm::Function *personality = module.getFunction("__gxx_personality_v0");
    

    You then create the landingpad with that personality and define its type:

    llvm::LandingPadInst *caughtResult = 
      builder.CreateLandingPad(ourCaughtResultType,
                               personality,
                               numExceptionsToCatch,
                               "landingPad");
    

    Setting up the types to catch:

    for (unsigned i = 0; i < numExceptionsToCatch; ++i) {
      // Set up type infos to be caught
      caughtResult->addClause(module.getGlobalVariable(
                              ourTypeInfoNames[exceptionTypesToCatch[i]]));
    }
    

    And signalling it’s a cleanup handler:

    caughtResult->setCleanup(true);
    

    This is it, I believe; now you can get the exception itself:

    llvm::Value *unwindException = builder.CreateExtractValue(caughtResult, 0);
    

    The ExceptionDemo.cpp 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:

    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->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);
    

    Finally, an additional example, along with explanations, is available on the blog post that introduced the new exception handling mechanism.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two basic questions. The first one is about function in other classes.
I have created a basic form in access that has a couple of buttons
I have created a music app that plays one of 9 sounds when an
I have a Rails 3.2.2 application using Ruby version 1.9.2. I have created basic
I have created a basic shape in HTML canvas element which works fine. The
I have created a basic site using ASP.NET routing according to Mike Ormond's example
I am newbie to Sencha Touch 2 and have created a basic applications using
We have created a simple wix project for a basic windows application. Everything builds
I have basic hello word example of Prime Faces. I have created dynamic web
I have some basic (stupid) questions about AWS EC2 instances or AMIs. I created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.