Skip to content

Loop IDs that do not count pseudo-loops - #9637

Draft
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:loop-ids-real-loops
Draft

tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:loop-ids-real-loops

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

Loop IDs of the form F.N number all loops of function F, including pseudo-loops: loops whose condition is constant false, such as the do { ... } while(0) that C macros commonly expand to. Adding or removing such a macro before a loop therefore changes the ID of that loop, and --unwindset settings silently stop applying to the intended loop. In mlkem-native, a change to debug-assertion macros turned polyvec_basemul_acc_montgomery_cached.3 into .0, and for 37 mainline commits an UNWINDSET entry .0 bounded the do-while(0) of a bounds-check macro instead of the loop it was meant for.

--show-loops now also shows a loop ID of the form F.L-N for each loop that is not a pseudo-loop, where N only counts such loops, and --unwindset accepts these IDs. Pseudo-loops have no such ID, so a loop added later never takes over an ID that belonged to a pseudo-loop. IDs of the form F.N keep their meaning; - cannot occur in labels, so the new form cannot be mistaken for a label either. As a bound for a pseudo-loop has no effect, --unwindset now warns when a loop ID refers to one.

Replaying the histories of mlkem-native and mldsa-native (1151 pairs of consecutive mainline commits that touch the sources or CBMC proofs, with ground truth from a line diff of each loop's header) shows that F.L-N would never have referred to the wrong loop for a loop named in an UNWINDSET entry. Over all 1544 loops that a commit changed, F.L-N referred to the wrong loop 7 times, compared to 19 times for F.N. F.L-N still changes when a real loop is inserted earlier in the same function.

  • 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.
  • 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.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Loop IDs of the form F.N number all loops of function F, including
pseudo-loops: loops whose condition is constant false, such as the
do { ... } while(0) that C macros commonly expand to. Adding or removing
such a macro before a loop therefore changes the ID of that loop, and
--unwindset settings silently stop applying to the intended loop. In
mlkem-native, a change to debug-assertion macros turned
polyvec_basemul_acc_montgomery_cached.3 into .0, and for 37 mainline
commits an UNWINDSET entry .0 bounded the do-while(0) of a bounds-check
macro instead of the loop it was meant for.

--show-loops now also shows a loop ID of the form F.L-N for each loop
that is not a pseudo-loop, where N only counts such loops, and
--unwindset accepts these IDs. Pseudo-loops have no such ID, so a loop
added later never takes over an ID that belonged to a pseudo-loop. IDs
of the form F.N keep their meaning; `-` cannot occur in labels, so the
new form cannot be mistaken for a label either. As a bound for a
pseudo-loop has no effect, --unwindset now warns when a loop ID refers
to one.

Replaying the histories of mlkem-native and mldsa-native (1151 pairs of
consecutive mainline commits that touch the sources or CBMC proofs, with
ground truth from a line diff of each loop's header) shows that F.L-N
would never have referred to the wrong loop for a loop named in an
UNWINDSET entry. Over all 1544 loops that a commit changed, F.L-N
referred to the wrong loop 7 times, compared to 19 times for F.N. F.L-N
still changes when a real loop is inserted earlier in the same
function.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@codecov

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.14286% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.36%. Comparing base (cce28f5) to head (e2dbd3b).
⚠️ Report is 4 commits behind head on develop.

Files with missing lines Patch % Lines
jbmc/src/jbmc/jbmc_parse_options.cpp 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9637      +/-   ##
===========================================
+ Coverage    81.34%   81.36%   +0.01%     
===========================================
  Files         1727     1728       +1     
  Lines       191715   191809      +94     
  Branches        73       73              
===========================================
+ Hits        155950   156062     +112     
+ Misses       35765    35747      -18     

☔ 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.

@kroening

kroening commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

Should we not pursue the idea of a "structural hash" ID for loops?

The pseudo-loops then don't really bother anymore, and loop IDs might be more stable.

This branch has not been deployed

No deployments
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