Repository navigation
Description
Summary
The CBMC SMT2 backend appears to encode pointer arithmetic incorrectly when the pointee has zero size.
For pointer addition, the element count is not scaled by the pointee size when element_size == 0. As a result, zero-sized pointees are effectively treated as one-byte elements, and pointer arithmetic can change the modeled address unexpectedly.
This affects ordinary ZSTs such as () as well as over-aligned zero-sized types.
Environment
- CBMC: 6.11.0
- SMT solver: CVC5 1.3.0
- Frontend: Rust through Kani
- Rust toolchain: nightly-2026-11-18
- Kani upstream base:
c25a57bcbf8c8af41617e7171a535a3518ce514a
Reproducer
The following Kani harness demonstrates the issue with an ordinary zero-sized pointee:
#[kani::proof]
#[kani::solver(cvc5)]
fn zst_wrapping_offset_is_identity() {
let mut byte = 0u8;
let p = (&raw mut byte).cast::<()>();
let n: isize = kani::any();
let shifted = p.wrapping_offset(n);
kani::assert(shifted == p, "ZST pointer address is preserved");
}The same behavior was reproduced with an over-aligned zero-sized pointee.
The reproducer uses Kani to generate the CBMC verification model. A minimized GOTO or SMT2 artifact can be provided if useful.
Expected behavior
For a zero-sized pointee, the byte displacement is:
count * sizeof(T) = count * 0 = 0
Therefore, pointer arithmetic should preserve the original pointer address for every offset.
The pointer should also retain its original allocation identity.
Actual behavior
On the CBMC 6.11.0 SMT2 path with CVC5, the pointer equality assertion fails on the unmodified Kani base for both () and an over-aligned ZST.
The equivalent harnesses pass with the default SAT backend.
Suspected cause
The issue appears to be in the SMT2 pointer-plus encoding in:
src/solvers/smt2/smt2_conv.cpp
The element count is only scaled when element_size >= 2. For a zero-sized pointee, the index is left unscaled, effectively producing one-byte pointer arithmetic instead of zero-byte displacement.
Scope
The issue was observed through Kani's CBMC SMT2 path. The default SAT backend handles the same cases correctly.
It may affect other producers of pointer-plus expressions involving zero-sized pointees as well.
Additional validation
The Kani regression also verifies that:
- The original pointer and allocation identity are preserved after the fix.
- Writes through the resulting ZST-derived pointer remain visible.
- Symbolic offsets do not change the pointer.
- Existing non-ZST out-of-bounds checks remain effective.
The Kani-side workaround is available in: model-checking/kani#5202
Activity