Skip to content

Reset memory initialization state in automatic harnesses - #5183

Merged
feliperodri merged 3 commits into
model-checking:mainfrom
Tiramisu-Cake:fix/autoharness-uninit-reset
Nov 20, 2026
Merged

feliperodri merged 3 commits into
model-checking:mainfrom
Tiramisu-Cake:fix/autoharness-uninit-reset

Conversation

@Tiramisu-Cake

Copy link
Copy Markdown
Contributor

-Z uninit-checks sets up its memory initialization state at the start of #[kani::proof] and #[kani::proof_for_contract] harnesses, but not in harnesses generated by kani autoharness: is_harness only looks for those two attributes. As a result, kani autoharness -Z uninit-checks does not report uninitialized reads; on main, a function that reads a padding byte through a raw pointer verifies.

is_harness now also recognizes the automatic harness intrinsic.

Testing

tests/script-based-pre/autoharness_uninit_reset runs kani autoharness -Z uninit-checks on two functions over a #[repr(C)] struct with padding. One reads a padding byte and now fails with "Reading from an uninitialized pointer". The other writes the byte first and verifies.

Standard workflows on this head in my fork: run. On macOS 15 Intel the only failure is cargo_autoharness_multichareq_searcher (#5162), also after a rerun; fail-fast then cancels the macOS 15 job.

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

Disclosure: this change and description were prepared with the help of AI assistants.

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 were identified for the autoharness initialization-tracking fix.

No open issues 🎉

What changed in this PR

Fixes memory-initialization tracking for kani autoharness -Z uninit-checks so generated harnesses report uninitialized reads, matching manual proof harness behavior.

Changes:

  • Recognizes the automatic harness intrinsic as an entry point requiring initialization-state setup.
  • Adds a regression test checking that reading a padding byte fails, while writing it before reading succeeds.
File Description
tests/​script-based-pre/​autoharness_uninit_reset/​run.sh Runs both cases and checks their exit statuses.
tests/​script-based-pre/​autoharness_uninit_reset/​main.rs Defines uninitialized and initialized padding-read cases.
tests/​script-based-pre/​autoharness_uninit_reset/​expected Records the expected diagnostic and verification outcomes.
tests/​script-based-pre/​autoharness_uninit_reset/​config.yml Registers the script and expected output.
kani-compiler/​src/​kani_middle/​transform/​check_uninit/​ptr_uninit/​mod.rs Extends harness detection to automatic harnesses.

Review effort: Balanced

# Conflicts:
#	kani-compiler/src/kani_middle/transform/check_uninit/ptr_uninit/mod.rs
@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 Nov 18, 2026

@feliperodri feliperodri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this is the right fix. is_harness decides where UninitPass initializes the shadow memory, and automatic harnesses keep the AutomaticHarness intrinsic's DefId, so matching it covers every generated harness. Without it, kani autoharness -Z uninit-checks reported no uninitialized reads at all. The new test pins both directions (a padding read fails, a written byte verifies), and it passes on the Linux regression jobs. Approving.

The macos-15-intel failures (cargo_autoharness_bounds, cargo_autoharness_wtf8) can't come from this change: neither test passes -Z uninit-checks, and UninitPass only runs with it. I've re-run the job.

@feliperodri feliperodri added [C] Bug This is a bug. Something isn't working. [F] Soundness Kani failed to detect an issue Z-Autoharness Issue related to autoharness subcommand labels Nov 20, 2026
@feliperodri
feliperodri added this pull request to the merge queue Nov 20, 2026
@feliperodri feliperodri removed their assignment Nov 20, 2026
Merged via the queue into model-checking:main with commit 6a23aed Nov 20, 2026
41 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[C] Bug This is a bug. Something isn't working. [F] Soundness Kani failed to detect an issue Z-Autoharness Issue related to autoharness subcommand 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.

3 participants