Repository navigation
Keep delayed UB instrumentation specific to each harness - #5195
feliperodri merged 3 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the change isolating uninitialized-memory instrumentation caches per proof harness.
No open issues 🎉
What changed in this PR
Keeps delayed uninitialized-memory instrumentation specific to each proof harness, preventing cached transformations from causing false failures in other harnesses within the same codegen unit.
Changes:
- Makes
BodyTransformationcloneable and gives each harness its own cache when-Z uninit-checksis enabled. - Preserves shared caching when uninitialized-memory checks are disabled.
- Adds regression coverage comparing standalone and paired harnesses across two shared call chains, while checking that uninitialized reads remain detected.
| File | Description |
|---|---|
tests/script-based-pre/delayed-shared-body/test.sh |
Runs the Python regression checker. |
tests/script-based-pre/delayed-shared-body/src/lib.rs |
Defines initialized and uninitialized harnesses with shared call paths. |
tests/script-based-pre/delayed-shared-body/expected |
Records the regression test’s success message. |
tests/script-based-pre/delayed-shared-body/control.rs |
Provides an independent uninitialized-padding read control. |
tests/script-based-pre/delayed-shared-body/config.yml |
Registers the script and expected output. |
tests/script-based-pre/delayed-shared-body/check.py |
Compares harness results and properties with and without uninitialized-memory checks. |
tests/script-based-pre/delayed-shared-body/Cargo.toml |
Defines the test crate and call-path selection feature. |
kani-compiler/src/kani_middle/transform/mod.rs |
Enables cloning of body transformations. |
kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs |
Selects harness-local or shared transformations based on the uninitialized-memory check flag. |
Review effort: Balanced
feliperodri
left a comment
There was a problem hiding this comment.
Thanks, good catch. The delayed UB pass instruments bodies for the targets of the harness being compiled, so a body cached for one harness is wrong for the next one in both directions:
- Extra instrumentation from another harness gives the false failure your test shows.
- Missing instrumentation would drop a check the later harness needs.
A harness-local copy of the unit's transformer under -Z uninit-checks fixes both, and leaving the shared cache alone without the flag keeps every other run unchanged. The test checks each harness alone and together, with and without the flag, so the cross-harness case is pinned. Approving.
Non-blocking: under -Z uninit-checks each harness now clones the whole warmed cache, bodies included, and re-transforms what the previous harnesses had already cached. That's fine for typical crates. On crates with many harnesses, such as verify-rust-std's intrinsics::verify with 394, it might show up in compile time. If it does, a follow-up could keep only the bodies the delayed UB pass changed harness-local, on top of the shared cache.
The red compile-timer-short check failed in the comparison step (compile-analyzer). Those benchmarks don't pass -Z uninit-checks, and without it this change keeps the shared cache as before, so it isn't measuring this change. I've re-run it.
0601bc5
On
main,cargo kani -Z uninit-checkscan fail an initialized read when two harnesses reach the same function. The delayed UB pass instruments function bodies for the analysis targets of the harness being compiled, and the result enters the body cache shared by all harnesses in the codegen unit. A later harness that reaches the same function reuses that body. In the regression test,initialized_control_harnessreads an initializedu64: onmain, it verifies alone and fails when paired withdelayed_harness, which writes a padded struct through a pointer cast and calls the same read function.With
-Z uninit-checks, this change gives each harness its own copy of the unit's body cache, so the delayed UB pass and codegen of one harness never see bodies instrumented for another. Without the flag, harnesses keep sharing the cache as before, so other runs pay nothing extra. The newscript-based-pre/delayed-shared-bodytest verifies each harness alone and both together, through two shared call chains, with and without-Z uninit-checks, and checks that the uninitialized read is still reported.Testing: CI in my fork: regression on Linux x86_64, Linux Arm and macOS Intel, documentation, perf, benchcomp, LLBC, format and Clippy passed. The macOS arm64 job did not get a runner. Cargo Deny fails on the new
chronoadvisory (RUSTSEC-2026-0543); this change does not touch dependencies.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.