Repository navigation
Index the outer array first for a C + K * i byte offset - #9627
Draft
tautschnig wants to merge 2 commits into
Draft
tautschnig wants to merge 2 commits into
tautschnig wants to merge 2 commits into
Conversation
For an offset C + x, get_subexpression_at_offset() first looked at the
member at offset C and, when that was element 0 of an inner array, indexed
that inner array with x. When x is K * i with K a multiple of the outer
element size, x selects the outer element instead: i * 16 + 8 into an array
of { uint64_t t; uint8_t node[8]; } became a[0].node[i * 16] rather than
a[i].node[0]. A read then gave an unconstrained value and a write was
lost, so false assertions verified (diffblue#9391).
For K * i + C and C + K * i (K a multiple of the element size, C a
constant), index the array with K / elem_size * i + C / elem_size and look
at offset C % elem_size within that element. Offsets with a non-constant
remainder are resolved as before.
The KNOWNBUG tests are the remaining case: a byte offset that, unlike a
typed in-bounds access, crosses the element or member it is resolved into.
Cherry-picked from d5a4344 on branch fix-subexpression-at-symbolic-offset
of https://github.com/ocochard/cbmc (the fix proposed in diffblue#9391), with the
offsets adapted to bytest, which develop now uses.
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
A write through a pointer into a three-dimensional array with a symbolic outer index was lost, and a read gave an unconstrained value: for char c[2][3][10], d = c[n][1] is at byte offset n * 30 + 10, and get_subexpression_at_offset() resolved d[0] as c[0][1][n * 30] instead of c[n][1][0]. cbmc then failed the true assertion c[n][1][0] == 'i' and proved the false one n == 0 || c[1][1][0] != 'i'. The same happens for a two-dimensional array member of a struct array element. The cause is the one of diffblue#9391 (the "C + x" branch indexing the inner array at offset C with x), fixed by the previous commit; these tests cover the cases with arrays of arrays. CBMC's own SMT solver (--cprover-smt2) fails these assertions also when the program accesses c[n][2][0] directly, without a pointer, and the incremental SMT back end does not support the struct, so the tests are tagged broken-cprover-smt-backend and no-new-smt accordingly. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Collaborator
|
Can we consolidate the tests? |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #9627 +/- ##
===========================================
+ Coverage 81.29% 81.34% +0.04%
===========================================
Files 1725 1727 +2
Lines 191680 191764 +84
Branches 73 73
===========================================
+ Hits 155835 155987 +152
+ Misses 35845 35777 -68 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
tautschnig
added a commit
to tautschnig/cbmc
that referenced
this pull request
Dec 3, 2026
The wrong proof of ~/bench/defects/union-copy-stale (also on upstream develop 2c585e2e9dd and cce28f5): with a global union x of an array member, `x.a[i] = 5; y = x;` at a non-constant i gave y the union's value from before the write, so that `assert(y.a[i] != 5)` was proved and `assert(y.a[i] == 5)` failed. Field sensitivity divided x into the symbols of its members, the write updated only that of x.a, and the copy took the symbol of x as a whole. Local unions and constant indices were not affected, and neither the size of the array (also 600 elements, above field sensitivity's limit on the elements it divides) nor --max-field-sensitivity-array-size 0 mattered. PR diffblue#9544's second commit (cherry-picked as 6fab9e3: a write to a member of a union updates the union as a whole) fixes it; diffblue#9627 does not (its head, 76c285a, gives the same wrong proof). The test fails with the build of 2c86ff0 and passes now. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For an offset C + x, get_subexpression_at_offset() first looked at the
member at offset C and, when that was element 0 of an inner array, indexed
that inner array with x. When x is K * i with K a multiple of the outer
element size, x selects the outer element instead: i * 16 + 8 into an array
of { uint64_t t; uint8_t node[8]; } became a[0].node[i * 16] rather than
a[i].node[0]. A read then gave an unconstrained value and a write was
lost, so false assertions verified (#9391).
For K * i + C and C + K * i (K a multiple of the element size, C a
constant), index the array with K / elem_size * i + C / elem_size and look
at offset C % elem_size within that element. Offsets with a non-constant
remainder are resolved as before.
The KNOWNBUG tests are the remaining case: a byte offset that, unlike a
typed in-bounds access, crosses the element or member it is resolved into.
This is @ocochard's proposed change cherry-picked from d5a4344 on branch fix-subexpression-at-symbolic-offset
of https://github.com/ocochard/cbmc (the fix proposed in #9391), with the
offsets adapted to bytest, which develop now uses.
Co-authored-by: Kiro kiro-agent@users.noreply.github.com