Skip to content

Keep delayed UB instrumentation specific to each harness - #5195

Merged
feliperodri merged 3 commits into
model-checking:mainfrom
Tiramisu-Cake:fix/per-harness-global-transforms
Nov 20, 2026
Merged

feliperodri merged 3 commits into
model-checking:mainfrom
Tiramisu-Cake:fix/per-harness-global-transforms

Conversation

@Tiramisu-Cake

Copy link
Copy Markdown
Contributor

On main, cargo kani -Z uninit-checks can 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_harness reads an initialized u64: on main, it verifies alone and fails when paired with delayed_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 new script-based-pre/delayed-shared-body test 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 chrono advisory (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.

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 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 BodyTransformation cloneable and gives each harness its own cache when -Z uninit-checks is 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 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, 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.

@feliperodri feliperodri added [C] Bug This is a bug. Something isn't working. [F] Spurious Failure Issues that cause Kani verification to fail despite the code being correct. 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
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 20, 2026
@feliperodri
feliperodri added this pull request to the merge queue Nov 20, 2026
Merged via the queue into model-checking:main with commit 0601bc5 Nov 20, 2026
36 of 37 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] Spurious Failure Issues that cause Kani verification to fail despite the code being correct. 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