1414#include " CIRGenFunction.h"
1515
1616#include " clang/AST/StmtVisitor.h"
17+ #include " clang/CIR/MissingFeatures.h"
1718#include " llvm/Support/SaveAndRestore.h"
1819
1920using namespace clang ;
@@ -344,7 +345,8 @@ void CIRGenFunction::enterCXXTryStmt(const CXXTryStmt &s, cir::TryOp tryOp,
344345
345346 // No exception decl indicates '...', a catch-all.
346347 mlir::Region *handler = &tryOp.getHandlerRegions ()[i];
347- catchScope->setHandler (i, cgm.getCXXABI ().getCatchAllTypeInfo (), handler);
348+ catchScope->setHandler (i, cgm.getCXXABI ().getCatchAllTypeInfo (), handler,
349+ s.getHandler (i));
348350
349351 // Under async exceptions, catch(...) needs to catch HW exception too
350352 // Mark scope with SehTryBegin as a SEH __try scope
@@ -385,8 +387,8 @@ void CIRGenFunction::exitCXXTryStmt(const CXXTryStmt &s, bool isFnTryBlock) {
385387
386388 // Copy the handler blocks off before we pop the EH stack. Emitting
387389 // the handlers might scribble on this memory.
388- SmallVector<EHCatchScope::Handler, 8 > handlers (
389- catchScope. begin (), catchScope.begin () + numHandlers);
390+ SmallVector<EHCatchScope::Handler> handlers (catchScope. begin (),
391+ catchScope.begin () + numHandlers);
390392
391393 ehStack.popCatch ();
392394
@@ -404,21 +406,20 @@ void CIRGenFunction::exitCXXTryStmt(const CXXTryStmt &s, bool isFnTryBlock) {
404406 }
405407
406408 bool hasCatchAll = false ;
407- for (unsigned i = numHandlers; i != 0 ; --i) {
408- hasCatchAll |= handlers[i - 1 ].isCatchAll ();
409- mlir::Region *catchRegion = handlers[i - 1 ].region ;
409+ for (auto &handler : llvm::reverse (handlers)) {
410+ hasCatchAll |= handler.isCatchAll ();
411+ mlir::Region *catchRegion = handler.region ;
412+ const CXXCatchStmt *catchStmt = handler.stmt ;
410413
411414 mlir::OpBuilder::InsertionGuard guard (builder);
412415 builder.setInsertionPointToStart (&catchRegion->front ());
413416
414- const CXXCatchStmt *catchStmt = s.getHandler (i - 1 );
415-
416417 // Enter a cleanup scope, including the catch variable and the
417418 // end-catch.
418419 RunCleanupsScope catchScope (*this );
419420
420421 // Initialize the catch variable and set up the cleanups.
421- // TODO: emitBeginCatch
422+ assert (! cir::MissingFeatures::catchParamOp ());
422423
423424 // Emit the PGO counter increment.
424425 assert (!cir::MissingFeatures::incrementProfileCounter ());
@@ -428,7 +429,7 @@ void CIRGenFunction::exitCXXTryStmt(const CXXTryStmt &s, bool isFnTryBlock) {
428429 emitStmt (catchStmt->getHandlerBlock (), /* useCurrentScope=*/ true );
429430 assert (emitResult.succeeded () && " failed to emit catch handler block" );
430431
431- // TODO( cir): This yeild should replaced by CatchParamOp once it upstreamed
432+ assert (! cir::MissingFeatures::catchParamOp ());
432433 cir::YieldOp::create (builder, tryOp->getLoc ());
433434
434435 // [except.handle]p11:
@@ -469,7 +470,7 @@ void CIRGenFunction::populateCatchHandlers(cir::TryOp tryOp) {
469470 EHScope &innermostEHScope = *ehStack.find (ehStack.getInnermostEHScope ());
470471 switch (innermostEHScope.getKind ()) {
471472 case EHScope::Terminate:
472- cgm.errorNYI (" emitLandingPad : terminate" );
473+ cgm.errorNYI (" populateCatchHandlers : terminate" );
473474 return ;
474475
475476 case EHScope::Catch:
@@ -491,29 +492,25 @@ void CIRGenFunction::populateCatchHandlers(cir::TryOp tryOp) {
491492 for (EHScopeStack::iterator i = ehStack.begin (), e = ehStack.end (); i != e;
492493 ++i) {
493494 switch (i->getKind ()) {
494- case EHScope::Cleanup: {
495+ case EHScope::Cleanup:
495496 cgm.errorNYI (" emitLandingPad: Cleanup" );
496497 return ;
497- }
498498
499- case EHScope::Filter: {
499+ case EHScope::Filter:
500500 cgm.errorNYI (" emitLandingPad: Filter" );
501501 return ;
502- }
503502
504- case EHScope::Terminate: {
503+ case EHScope::Terminate:
505504 cgm.errorNYI (" emitLandingPad: Terminate" );
506505 return ;
507- }
508506
509507 case EHScope::Catch:
510508 break ;
511- }
509+ } // end switch
512510
513511 EHCatchScope &catchScope = cast<EHCatchScope>(*i);
514- for (unsigned handlerIdx = 0 , he = catchScope.getNumHandlers ();
515- handlerIdx != he; ++handlerIdx) {
516- EHCatchScope::Handler handler = catchScope.getHandler (handlerIdx);
512+ for (const EHCatchScope::Handler &handler :
513+ llvm::make_range (catchScope.begin (), catchScope.end ())) {
517514 assert (handler.type .flags == 0 &&
518515 " landingpads do not support catch handler flags" );
519516
@@ -617,15 +614,14 @@ void CIRGenFunction::populateEHCatchRegions(EHScopeStack::stable_iterator scope,
617614// `getInvokeDestImpl`, in CIR we need the condition to know if the EH scope may
618615// throw exception or now.
619616bool CIRGenFunction::isCatchOrCleanupRequired () {
620- if (!ehStack.requiresCatchOrCleanup ())
621- return false ;
622-
623617 // If exceptions are disabled/ignored and SEH is not in use, then there is no
624618 // invoke destination. SEH "works" even if exceptions are off. In practice,
625619 // this means that C++ destructors and other EH cleanups don't run, which is
626620 // consistent with MSVC's behavior, except in the presence of -EHa
627621 const LangOptions &lo = cgm.getLangOpts ();
628622 if (!lo.Exceptions || lo.IgnoreExceptions ) {
623+ if (!lo.Borland && !lo.MicrosoftExt )
624+ return false ;
629625 cgm.errorNYI (" isInvokeDest: no exceptions or ignore exception" );
630626 return false ;
631627 }
@@ -634,7 +630,7 @@ bool CIRGenFunction::isCatchOrCleanupRequired() {
634630 if (lo.CUDA && lo.CUDAIsDevice )
635631 return false ;
636632
637- return true ;
633+ return ehStack. requiresCatchOrCleanup () ;
638634}
639635
640636// In classic codegen this function is equivalent to `getInvokeDestImpl`, in
0 commit comments