[clang] [CIR] Remove overly strict end_catch assertion in catch handler flattening (PR #193796)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 23 12:08:12 PDT 2026
================
@@ -1566,30 +1566,6 @@ class CIRTryOpFlattening : public mlir::OpRewritePattern<cir::TryOp> {
for (mlir::Block &block : llvm::make_range(handlerEntry->getIterator(),
insertBefore->getIterator())) {
if (auto yieldOp = dyn_cast<cir::YieldOp>(block.getTerminator())) {
- // Verify that end_catch is the last non-branch operation before
----------------
adams381 wrote:
The assertion fires when compiling Eigen's sparselu.cpp (heavily-templated sparse matrix decomposition code with exceptions enabled). The catch handler in that code has deeply nested cleanup scopes from template-instantiated destructors, and after cleanup scope flattening the yield's predecessor chain includes blocks with multiple predecessors — the assertion's `getSinglePredecessor()` walk returns null and fails.
I was unable to reduce the Eigen case to a minimal standalone reproducer because it depends on several other CIR fixes landing first (#193596, #193611, #193615) to get past CIRGen — without all of those, the file hits earlier assertion failures before reaching FlattenCFG.
The assertion is a structural invariant check — it verifies that `end_catch` is the last meaningful operation before the handler's yield, with only branches in between. The code that follows the assertion (`replaceOpWithNewOp<cir::BrOp>(yieldOp, continueBlock)`) is unconditional and does not depend on the assertion's condition. The `end_catch` has already been correctly placed by cleanup scope flattening; the assertion was just double-checking the block topology, and its walk was too strict for complex multi-predecessor paths.
Three options:
1. **Keep this PR as-is** — remove the assertion since it's a verification check that doesn't guard any code path, and the walk assumption (single-predecessor chain) was too narrow.
2. **Soften to a comment** — replace the assertion with a comment explaining the expected invariant, without enforcing it.
3. **Wait for dependencies** — once #193611 and #193615 land, I can try again to reduce the Eigen case to a minimal reproducer and add a proper test.
Happy to go with whichever you prefer.
https://github.com/llvm/llvm-project/pull/193796
More information about the cfe-commits
mailing list