Repository navigation
Reset memory initialization state in automatic harnesses - #5183
Conversation
There was a problem hiding this comment.
🟢 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
feliperodri
left a comment
There was a problem hiding this comment.
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.
6a23aed
-Z uninit-checkssets up its memory initialization state at the start of#[kani::proof]and#[kani::proof_for_contract]harnesses, but not in harnesses generated bykani autoharness:is_harnessonly looks for those two attributes. As a result,kani autoharness -Z uninit-checksdoes not report uninitialized reads; onmain, a function that reads a padding byte through a raw pointer verifies.is_harnessnow also recognizes the automatic harness intrinsic.Testing
tests/script-based-pre/autoharness_uninit_resetrunskani autoharness -Z uninit-checkson 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.