Commit fd838b2
Fix loop-contract transform for post-#145513 deref temporaries (#4659)
rust-lang/rust#145513 (first shipped in nightly-2025-10-13) removed
`Rvalue::CopyForDeref` from runtime MIR: the compiler-generated deref
temporaries that destructuring patterns like `for (i, &p) in ...`
introduce are now assigned via plain `Rvalue::Use(Operand::Copy)`.
`replace_first_pat_by_nth_pat` distinguished pattern bindings from deref
temporaries purely by rvalue kind, so with the new MIR shape a deref
temporary is treated like a pattern binding: its assignment is
redirected to the nthpat temporary, leaving the firstpat temporary
uninitialized, and the subsequent dereference of that temporary yields
spurious "dereference failure" checks (see #4658 for the full analysis).
This is what currently breaks the `num::dec2flt::decimal_seq` proofs in
model-checking/verify-rust-std#530.
The fix pairs up only user variables (pattern bindings, as identified
via `var_debug_info`) in the firstprj→nthprj map, and handles unmapped
`Use(Copy)` assignments sourced from the firstpat variable exactly like
the old `CopyForDeref` case: keep the assigned place, only re-point the
rvalue at the nthpat variable. The `CopyForDeref` match arm is kept for
defensiveness.
Manual testing performed:
* New regression test
`tests/expected/loop-contract/for_loop_ref_pattern.rs` (modelled after
`number_of_digits_decimal_left_shift` from the Rust standard library)
fails before the fix with 6 spurious dereference failures and passes
with it.
* Full `expected` suite: 404 passed / 1 failed — the failure
(`shadow/unsupported_num_objects`) is pre-existing and also fails on
unmodified `main` (unsupported `__rust_alloc_error_handler` foreign
function).
* Backported the patch onto d4df833 (the Kani commit verify-rust-std
is about to pin) and verified that the two failing verify-rust-std
harnesses (`decimal_seq_verify::check_left_shift`,
`decimal_seq_verify::check_number_of_digits_decimal_left_shift`) verify
successfully.
Resolves #4658
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
---------
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>1 parent 1b1d6c1 commit fd838b2
3 files changed
Lines changed: 89 additions & 8 deletions
File tree
- kani-compiler/src/kani_middle/transform
- tests/expected/loop-contract
Lines changed: 30 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
304 | 313 | | |
305 | 314 | | |
306 | 315 | | |
307 | 316 | | |
| 317 | + | |
308 | 318 | | |
309 | 319 | | |
310 | 320 | | |
| |||
342 | 352 | | |
343 | 353 | | |
344 | 354 | | |
345 | | - | |
346 | 355 | | |
347 | 356 | | |
348 | 357 | | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
356 | 378 | | |
357 | 379 | | |
358 | 380 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
0 commit comments