Registry Mirror
Skip to content

Conversation

@melver

@melver melver commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Consider an inner loop that is entered by an unconditional forward goto:

  int i = 0;
outer:;
  int j = 0;
  goto inner;
inner:
  j++;
  if(j < 3)
    goto inner;
  i++;
  if(i < 2)
    goto outer;

The inner loop runs 3 times per outer iteration, so --unwind 3 should suffice. symex_transition resets a loop's unwinding counter when it enters the loop, i.e., on a forward transition to the loop head, or on a backward one from outside the loop. symex_goto, however, has a fast path for unconditional gotos taken while the guard is true, which always reported the transition as backward. A forward goto into the loop head thus did not reset the counter, and the inner loop kept counting across outer iterations. With --unwinding-assertions this reported a spurious unwinding failure even at --unwind 4; without, unwinding stopped too early. Entering the loop by fallthrough was not affected.

Backward gotos with a true condition return before reaching the fast path, so it only sees forward gotos. Pass the actual direction of the goto.

Assisted-by: Antigravity


  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.02%. Comparing base (826c1c7) to head (dc87b8c).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9398      +/-   ##
===========================================
- Coverage    81.02%   81.02%   -0.01%     
===========================================
  Files         1723     1723              
  Lines       191314   191314              
  Branches        73       73              
===========================================
- Hits        155020   155017       -3     
- Misses       36294    36297       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Consider an inner loop that is entered by an unconditional forward goto:

    int i = 0;
  outer:;
    int j = 0;
    goto inner;
  inner:
    j++;
    if(j < 3)
      goto inner;
    i++;
    if(i < 2)
      goto outer;

The inner loop runs 3 times per outer iteration, so --unwind 3 should
suffice. symex_transition resets a loop's unwinding counter when it
enters the loop, i.e., on a forward transition to the loop head, or on a
backward one from outside the loop. symex_goto, however, has a fast path
for unconditional gotos taken while the guard is true, which always
reported the transition as backward. A forward goto into the loop head
thus did not reset the counter, and the inner loop kept counting across
outer iterations. With --unwinding-assertions this reported a spurious
unwinding failure even at --unwind 4; without, unwinding stopped too
early. Entering the loop by fallthrough was not affected.

Backward gotos with a true condition return before reaching the fast
path, so it only sees forward gotos. Pass the actual direction of the
goto.
@melver
melver force-pushed the fix-symex-forward-goto-loop-entry branch from 2e0d1e1 to dc87b8c Compare November 8, 2026 13:36
@melver

melver commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

I assume one of you needs to press "merge", because I do not have permissions?

@peterschrammel

Copy link
Copy Markdown
Member

Great find, @melver!

@peterschrammel
peterschrammel merged commit 57c8ad7 into diffblue:develop Nov 13, 2026
39 of 43 checks passed
tautschnig added a commit to tautschnig/cbmc that referenced this pull request Nov 23, 2026
symex_goto takes its unconditional-goto fast path either when the state
guard is true or when doing path exploration. The test added in diffblue#9398
only uses constants, so its guard is always true and it never exercises
the second case. Add a variant where the guard at the forward goto into
the inner loop's head is not true on the second outer iteration, and run
it with --paths lifo. Without the fix from diffblue#9398 this test fails with a
spurious unwinding-assertion failure for the inner loop.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig added a commit to tautschnig/cbmc that referenced this pull request Nov 23, 2026
With path exploration (--paths), symex_goto saves both successors of a
branch. When the saved jump-target path of a backward goto is resumed,
the two successors are swapped, so state_pc is the instruction following
the goto rather than the goto's target. symex_goto nevertheless told
symex_transition that this transition was a backward goto. If the next
instruction is a loop head, symex_transition then only resets that
loop's unwinding counter when arriving from beyond the loop's back edge,
which never holds for an instruction preceding the loop. The counter
thus kept counting across entries of the loop, yielding spurious
unwinding-assertion failures (or unwinding stopped too early without
--unwinding-assertions).

This is the same mix-up of transition direction as was fixed for the
unconditional-goto fast path in diffblue#9398. The transition to state_pc is
backward only if state_pc is the target of a backward goto.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig added a commit to tautschnig/cbmc that referenced this pull request Nov 23, 2026
The three-argument overload of symex_transition had no documentation,
yet its is_backwards_goto flag decides whether a transition onto a loop
head resets that loop's unwinding counter. Passing the wrong value
caused both the bug fixed in diffblue#9398 and the one fixed for resumed
fall-through paths of backward gotos. Spell out which transitions count
as backward.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig added a commit to tautschnig/cbmc that referenced this pull request Nov 23, 2026
With path exploration (--paths), symex_goto saves both successors of a
branch. When the saved jump-target path of a backward goto is resumed,
the two successors are swapped, so state_pc is the instruction following
the goto rather than the goto's target. symex_goto nevertheless told
symex_transition that this transition was a backward goto. If the next
instruction is a loop head, symex_transition then only resets that
loop's unwinding counter when arriving from beyond the loop's back edge,
which never holds for an instruction preceding the loop. The counter
thus kept counting across entries of the loop, yielding spurious
unwinding-assertion failures (or unwinding stopped too early without
--unwinding-assertions).

This is the same mix-up of transition direction as was fixed for the
unconditional-goto fast path in diffblue#9398. The transition to state_pc is
backward only if state_pc is the target of a backward goto.

The three-argument overload of symex_transition had no documentation,
yet its is_backwards_goto flag decides whether a transition onto a loop
head resets that loop's unwinding counter. Spell out which transitions
count as backward.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
kroening pushed a commit that referenced this pull request Nov 26, 2026
symex_goto takes its unconditional-goto fast path either when the state
guard is true or when doing path exploration. The test added in #9398
only uses constants, so its guard is always true and it never exercises
the second case. Add a variant where the guard at the forward goto into
the inner loop's head is not true on the second outer iteration, and run
it with --paths lifo. Without the fix from #9398 this test fails with a
spurious unwinding-assertion failure for the inner loop.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
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