[clang] [CIR] Fix lost catch clauses on EH landing pads (PR #205638)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 25 08:55:27 PDT 2026
================
@@ -397,17 +474,40 @@ mlir::LogicalResult ItaniumEHLowering::lowerFunc(cir::FuncOp funcOp) {
/// \p ehTokenMap is shared across all initiates in the function so that block
/// arguments reachable from multiple sibling initiates are registered once.
mlir::LogicalResult ItaniumEHLowering::lowerEhInitiate(
- cir::EhInitiateOp initiateOp, EhTokenMap &ehTokenMap,
- SmallVectorImpl<mlir::Operation *> &deadOps) {
+ cir::EhInitiateOp initiateOp,
+ llvm::ArrayRef<cir::EhDispatchOp> reachedDispatches, bool reachesCleanup,
+ EhTokenMap &ehTokenMap, SmallVectorImpl<mlir::Operation *> &deadOps) {
mlir::Value rootToken = initiateOp.getEhToken();
- // Create the inflight_exception without a catch_type_list. The catch types
- // will be set once we encounter the dispatch during the traversal below.
+ // The catch clauses for this landing pad come from the dispatches its
+ // exception reaches (computed read-only by the caller before any destructive
+ // lowering). For nested try/catch the exception can reach several dispatches
+ // innermost first, so the landing pad lists their catch types in that order
+ // (matching classic CodeGen), stopping at a catch-all since nothing escapes
+ // it. Deriving this from the original EH graph -- rather than during the
+ // destructive token-graph traversal below -- keeps it correct regardless of
+ // the order in which sibling/nested initiates are lowered.
+ mlir::ArrayAttr catchTypeList;
+ bool catchAll = false;
+ SmallVector<mlir::Attribute> typeSymbols;
+ for (cir::EhDispatchOp dispatch : reachedDispatches) {
+ if (mlir::ArrayAttr catchTypes = dispatch.getCatchTypesAttr())
+ for (mlir::Attribute attr : catchTypes)
+ typeSymbols.push_back(
+ mlir::cast<cir::GlobalViewAttr>(attr).getSymbol());
+ if (dispatch.getDefaultIsCatchAll()) {
+ catchAll = true;
+ break;
----------------
adams381 wrote:
Added the comment and `assert(dispatch == reachedDispatches.back())` -- the catch-all is always the last reachable dispatch.
https://github.com/llvm/llvm-project/pull/205638
More information about the cfe-commits
mailing list