llvm-project
b0c2dc0c - [flang][PFT-to-MLIR] allocate missing body blocks in `createEmptyRegionBlocks` (#210950)

Commit
110 days ago
[flang][PFT-to-MLIR] allocate missing body blocks in `createEmptyRegionBlocks` (#210950) Problem ------- Under -mmlir --wrap-unstructured-constructs-in-execute-region, branch lowering hit a null Evaluation::block for body statements inside an OpenMP loop. genMultiwayBranch tripped Bridge.cpp: Assertion `block && "missing multiway branch block"' failed and genFIR(SelectCaseStmt) tripped Bridge.cpp: Assertion `e->block && "missing CaseStmt block"' failed The wrap machinery decides an unstructured DO/IF is wrappable and stops propagating its isUnstructured flag to the enclosing OpenMPConstruct. The OMP construct's isUnstructured stays false, so the top-level createEmptyBlocks treats it as a structured directive with nested evaluations — it allocates only the OMP construct's first-nested block and does not recurse into the DO body. Then OMP loop lowering takes over the body via createEmptyRegionBlocks, which was written to *re-parent* pre-existing blocks into its region and silently skipped evals whose .block was still null. Body targets (e.g. label 17's ContinueStmt, or a SelectCase's CaseStmts) therefore had no block when the consumer read evalOfLabel(...).block, tripping the asserts. Solution -------- Restore the invariant that consumers of eval.block can trust it at lowering time. In createEmptyRegionBlocks (DirectivesCommon.h), when an eval has isNewBlock but no .block, create one in the current region alongside the existing re-parenting path. The OMP lowering path then finds pre-allocated blocks for the whole body — matching the state that existed before the wrap feature changed isUnstructured propagation — without any lazy-allocation logic at consumer sites. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Author
Parents
Loading