Skip to content

Distinguish constant offsets into the same object when dereferencing - #9388

Open
melver wants to merge 1 commit into
diffblue:developfrom
melver:fix-value-set-deref-offset-guard
Open

melver wants to merge 1 commit into
diffblue:developfrom
melver:fix-value-set-deref-offset-guard

Conversation

@melver

@melver melver commented Nov 3, 2026

Copy link
Copy Markdown

Consider a pointer that may point to an array as a whole, or to one of its elements:

uint8_t raw[16] = {0};
raw[12] = 0xAA;
const void *p = c ? (const void *)(raw + 12) : (const void *)&raw;
assert(*(const uint8_t *)p == (c ? 0xAA : 0));

The value set of p then has two entries for the same object raw: one at offset 12 (from raw + 12) and one at offset 0 (from &raw). Dereferencing p builds a case split over these entries, where each case is guarded by a condition that the pointer refers to that entry. For an entry at offset 0 that guard is p == &raw, but for an entry at any other offset it was only same_object(p, &raw), which is also true when p == &raw. The value for the offset-12 entry, raw[12], is built for that constant offset, though, so the case split read raw[12] for p == &raw, and the assertion failed for c == 0.

When the offset of the entry is constant, also require the offset of the pointer to match it. Entries with a non-constant offset keep using just same_object, as their value is built from the pointer's actual offset.

Assisted-by: Antigravity


  • Each commit message has a non-empty body, explaining why the change was made.
  • 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/
    (bug fix only)
  • 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). (no performance claims)
  • 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.

Consider a pointer that may point to an array as a whole, or to one of
its elements:

    uint8_t raw[16] = {0};
    raw[12] = 0xAA;
    const void *p = c ? (const void *)(raw + 12) : (const void *)&raw;
    assert(*(const uint8_t *)p == (c ? 0xAA : 0));

The value set of p then has two entries for the same object raw: one at
offset 12 (from raw + 12) and one at offset 0 (from &raw). Dereferencing
p builds a case split over these entries, where each case is guarded by
a condition that the pointer refers to that entry. For an entry at
offset 0 that guard is p == &raw, but for an entry at any other offset
it was only same_object(p, &raw), which is also true when p == &raw.
The value for the offset-12 entry, raw[12], is built for that constant
offset, though, so the case split read raw[12] for p == &raw, and the
assertion failed for c == 0.

When the offset of the entry is constant, also require the offset of the
pointer to match it. Entries with a non-constant offset keep using just
same_object, as their value is built from the pointer's actual offset.
@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.91%. Comparing base (a521901) to head (8bfed85).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9388      +/-   ##
===========================================
- Coverage    80.91%   80.91%   -0.01%     
===========================================
  Files         1719     1719              
  Lines       190344   190350       +6     
  Branches        73       73              
===========================================
+ Hits        154022   154025       +3     
- Misses       36322    36325       +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.

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.

1 participant