Skip to content

Do not reuse a static's storage for an equal-bytes constant - #5089

Open
r-near wants to merge 1 commit into
model-checking:mainfrom
r-near:fix-static-const-alias
Open

r-near wants to merge 1 commit into
model-checking:mainfrom
r-near:fix-static-const-alias

Conversation

@r-near

@r-near r-near commented Oct 28, 2026

Copy link
Copy Markdown

Statics were inserted into alloc_map, so codegen_const_allocation could return a static's address for a constant with the same initial bytes, and a store to the static then changed the constant (false proofs / false failures). This moves the insert so only constant allocations are cached.

Adds tests/kani/Static/static_const_same_bytes.rs, which fails before this change.

Resolves #5088

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

Statics were added to alloc_map, so a constant with the same initial
bytes could be codegen'd as a read of the static, and a store to the
static changed the constant. Only cache constant allocations.

Resolves model-checking#5088
@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Oct 28, 2026
@r-near
r-near marked this pull request as ready for review October 28, 2026 07:31
@r-near
r-near requested review from a team as code owners October 28, 2026 07:31
@feliperodri
feliperodri requested a balanced review from Copilot October 31, 2026 00:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the change separating constant allocations from static storage.

No open issues 🎉

What changed in this PR

Fixes #5088 by preventing constants from reusing a static’s storage when their initial bytes match, avoiding false verification results in Kani.

Changes:

  • Restricts allocation-cache insertion to constant allocations, keeping static storage separate.
  • Adds a regression harness checking that writes to equal-bytes statics do not change a constant’s value.
File Description
tests/​kani/​Static/​static_const_same_bytes.rs Tests that a constant remains unchanged after atomic static stores.
kani-compiler/​src/​codegen_cprover_gotoc/​codegen/​operand.rs Moves cache insertion from shared allocation code into constant allocation code.

Review effort: Balanced

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

Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Constant read from a static's storage when their initial bytes match: false proofs

2 participants