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
Contributor

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, compare the pointer with the address at that offset, (char *)&raw + 12, as the guard for offset 0 compares it with &raw. Comparing pointer_offset(p) with the offset instead would not work for negative offsets: pointer_offset does not sign-extend them, so the guard for, e.g., other - 1 would never hold. 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.

@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 81.34%. Comparing base (7401805) to head (a2a2ee4).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #9388   +/-   ##
========================================
  Coverage    81.34%   81.34%           
========================================
  Files         1727     1727           
  Lines       191753   191758    +5     
  Branches        73       73           
========================================
+ Hits        155986   155994    +8     
+ Misses       35767    35764    -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.

@melver
melver force-pushed the fix-value-set-deref-offset-guard branch from 8bfed85 to 194664e Compare November 8, 2026 13:36
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, compare the pointer with the
address at that offset, (char *)&raw + 12, as the guard for offset 0
compares it with &raw. Comparing pointer_offset(p) with the offset
instead would not work for negative offsets: pointer_offset does not
sign-extend them, so the guard for, e.g., other - 1 would never hold.
Entries with a non-constant offset keep using just same_object, as their
value is built from the pointer's actual offset.
@melver
melver force-pushed the fix-value-set-deref-offset-guard branch from 194664e to a2a2ee4 Compare December 4, 2026 16:10

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