[clang] [CIR] Fix remaining (part 2) FlattenCFG rewriter contract violations (PR #192503)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 16 11:26:47 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) {
----------------
erichkeane wrote:
Should this be its own function? I'd hate for these scopes to get out of sync.
https://github.com/llvm/llvm-project/pull/192503
More information about the cfe-commits
mailing list