← Contribution overview

Structured cleanup and control flow ยท PR #4710

Run block cleanup for unlabeled break and continue

Merged

Objective

Run block cleanup for unlabeled break and continue, including tail-position forms.

Why it was needed

break and continue can leave a block before its end, but values created in that block still need Drop.

The jumps must remain inside the block’s TRY_FINALLY_EXPR body so cleanup can run.

Tail-position forms such as { break } and { continue } must also be emitted as statements. Otherwise, gccrs creates the jump but never adds it to the block.

Main changes

  • Makes an unlabeled break return its lowered expression to the block instead of emitting it immediately.
  • Emits tail-position break and continue expressions as statements inside the block body.

Test case

Current limits

Labeled break and continue, and tail-position return cleanup, were left for follow-up work.

Issue #4717 tracks a case where break comes before a local declaration in the same loop scope and the local can be dropped twice.

View PR on GitHub ← Contribution overview