Skip to content

Fix BoogieToStrata: handle cross-nesting and backward gotos#655

Open
tautschnig wants to merge 1 commit intomainfrom
tautschnig/fix-boogie-to-strata
Open

Fix BoogieToStrata: handle cross-nesting and backward gotos#655
tautschnig wants to merge 1 commit intomainfrom
tautschnig/fix-boogie-to-strata

Conversation

@tautschnig
Copy link
Contributor

@tautschnig tautschnig commented Mar 25, 2026

Cross-nesting forward gotos: recursively collect goto targets from nested if/while bodies so wrapper blocks are created at the correct nesting level. Track enclosing wrapper labels to avoid emitting duplicate labeled blocks.

Backward gotos (loops): translate back-edges to while(true) loops instead of extending wrapper closeAt indices (which broke Strata's exit semantics). For each detected back-edge, the affected blocks are wrapped in while(true) with the back-edge target label wrapping the entire loop body, so 'exit ' acts as continue. Forward targets within the loop body use inner wrappers; forward exits to labels outside the loop propagate through the while as normal.

Add CrossNestingExit regression test covering:

  • CrossNestingForward: goto from inside if-branch to sibling block
  • BackwardGotoBuggy: demonstrates the old approach incorrectly passed a buggy assertion (g <= 2 after a doubling loop), while the new while-loop encoding correctly detects the bug
  • BackwardGotoLoop: simple backward goto forming a loop
  • CrossNestingInLoop: cross-nesting goto inside a loop body

Co-authored-by: Kiro [email protected]

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves the Boogie-to-Strata-Core translator’s handling of goto-driven control flow that crosses structured nesting boundaries, aiming to eliminate Strata type-check failures related to invalid exit targets.

Changes:

  • Recursively collects goto targets from within nested if/while bodies to drive wrapper-block creation at the appropriate nesting level.
  • Tracks “currently enclosing” wrapper labels to avoid emitting duplicate/shadowing labeled blocks.
  • Adds a new Boogie regression test (CrossNestingExit) and expected verification output.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
Tools/BoogieToStrata/Source/StrataGenerator.cs Adds nested goto-target collection and wrapper/label handling logic for cross-nesting (and attempted back-edge) scenarios.
Tools/BoogieToStrata/Tests/CrossNestingExit.bpl New regression test exercising cross-nesting exits and back-edge gotos.
Tools/BoogieToStrata/Tests/CrossNestingExit.expect Expected verifier output for the new regression test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Cross-nesting forward gotos: recursively collect goto targets from
nested if/while bodies so wrapper blocks are created at the correct
nesting level. Track enclosing wrapper labels to avoid emitting
duplicate labeled blocks.

Backward gotos (loops): translate back-edges to while(true) loops
instead of extending wrapper closeAt indices (which broke Strata's
exit semantics). For each detected back-edge, the affected blocks
are wrapped in while(true) with the back-edge target label wrapping
the entire loop body, so 'exit <label>' acts as continue. Forward
targets within the loop body use inner wrappers; forward exits to
labels outside the loop propagate through the while as normal.

Add CrossNestingExit regression test covering:
- CrossNestingForward: goto from inside if-branch to sibling block
- BackwardGotoBuggy: demonstrates the old approach incorrectly
  passed a buggy assertion (g <= 2 after a doubling loop), while
  the new while-loop encoding correctly detects the bug
- BackwardGotoLoop: simple backward goto forming a loop
- CrossNestingInLoop: cross-nesting goto inside a loop body

Co-authored-by: Kiro <[email protected]>
@tautschnig tautschnig force-pushed the tautschnig/fix-boogie-to-strata branch from 5352445 to 1db2cac Compare March 25, 2026 10:25
@tautschnig tautschnig enabled auto-merge March 25, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants