[clang] [CIR] Fix remaining (part 2) FlattenCFG rewriter contract violations (PR #192503)
Bruno Cardoso Lopes via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 16 12:11:46 PDT 2026
================
@@ -228,13 +228,19 @@ class CIRSwitchOpFlattening : public mlir::OpRewritePattern<cir::SwitchOp> {
mlir::LogicalResult
matchAndRewrite(cir::SwitchOp op,
mlir::PatternRewriter &rewriter) const override {
- // Cleanup scopes must be lowered before the enclosing switch so that
- // break inside them is properly routed through cleanup.
- // Fail the match so the pattern rewriter will process cleanup scopes first.
- bool hasNestedCleanup = op->walk([&](cir::CleanupScopeOp) {
- return mlir::WalkResult::interrupt();
- }).wasInterrupted();
- if (hasNestedCleanup)
+ // All nested structured CIR ops must be flattened before the switch.
+ // Break statements inside nested structured ops (scopes, ifs, ternaries,
+ // cleanup scopes) would create branches to blocks outside those ops'
+ // regions, which is invalid. Fail the match so the pattern rewriter will
+ // process them first.
+ bool hasNestedStructuredOps =
+ op->walk([&](mlir::Operation *nestedOp) {
----------------
bcardosolopes wrote:
Good point, better yet if I can arrange a way to get this out of tablegen generated stuff directly, let me see
https://github.com/llvm/llvm-project/pull/192503
More information about the cfe-commits
mailing list