Skip to content

Reject unstructured control flow inside critical regions#1048

Merged
jcp19 merged 1 commit into
atomicAndInvsfrom
claude/gobra-atomics-soundness-bwfbid
Jul 15, 2026
Merged

Reject unstructured control flow inside critical regions#1048
jcp19 merged 1 commit into
atomicAndInvsfrom
claude/gobra-atomics-soundness-bwfbid

Conversation

@jcp19

@jcp19 jcp19 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@jcp19
jcp19 force-pushed the claude/gobra-atomics-soundness-bwfbid branch from 7cb3f75 to 97ba463 Compare July 15, 2026 17:17
A `return`/`break`/`continue` inside a `critical` region jumps past the region's
closing `exhale` (which desugaring emits after the region body), so the opened
invariant's resources are inhaled but never given back - they leak to the caller.
In a ghost `opensInvariants` function this was accepted, because the
critical-region well-formedness check classifies every statement in a ghost
function as ghost (and thus allowed). Since `Invariant(p)` is duplicable, this
made it possible to extract an invariant's contents arbitrarily often and prove
`false`, e.g.:

    ghost opensInvariants requires Invariant(Cell{x}) ensures acc(x)
    func steal(x *int) {
        critical Cell{x} ( unfold Cell{x}(); return )
    }

Reject `return`/`break`/`continue` statements that have an enclosing critical
region, checked at the statement itself via `isEnclosingCritical`.

Add regression test atomics-critical-controlflow.gobra.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DVrhzyHHGEfmThbga93BED
@jcp19
jcp19 force-pushed the claude/gobra-atomics-soundness-bwfbid branch from 97ba463 to 6ab7e1a Compare July 15, 2026 20:01
@jcp19
jcp19 marked this pull request as ready for review July 15, 2026 20:09
@jcp19
jcp19 merged commit 3a9205d into atomicAndInvs Jul 15, 2026
3 of 4 checks passed
@jcp19
jcp19 deleted the claude/gobra-atomics-soundness-bwfbid branch July 15, 2026 21:08
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.

2 participants