Fix compiler crash on slice-modifies verified stubs (#4748) - #4749
Open
feliperodri wants to merge 1 commit into
Open
Fix compiler crash on slice-modifies verified stubs (#4748)#4749feliperodri wants to merge 1 commit into
feliperodri wants to merge 1 commit into
Conversation
…ng#4748) When a function contract modifies a whole slice (e.g. `#[kani::modifies(x)]` with `x: &mut [u8]`) and the contract is used as a verified stub via `#[kani::stub_verified]`, the compiler crashed while collecting reachable items: Failed to resolve `into_iter` with `GenericArgs([Ref(Slice(Slice(U8)), Mut)])` The `AnyModifiesPass` rewrites the `write_any` marker into one of `write_any_slim`/`write_any_slice`/`write_any_str` depending on the pointee type. For the slice case it resolved `write_any_slice<T>(slice: *mut [T])` using the marker's `instance_args`, which hold the *pointee* type `[T]` rather than the element type `T`. This produced `write_any_slice<[T]>` with argument `*mut [[T]]` (a doubled slice), whose `fill_with` body then failed to resolve. Resolve `write_any_slice` with the slice's element type instead. This path is only exercised in replace mode (`stub_verified`), which is why `proof_for_contract` harnesses were unaffected and the existing `modifies_fat_pointer` tests did not catch it. Resolves: model-checking#4748
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
#[kani::modifies(x)]on a whole-slice argument (e.g.x: &mut [u8]) crashed the compiler when the contract was reused as a verified stub via#[kani::stub_verified]. Reachability collection panicked with:i.e. a doubled slice
&mut [[u8]].Context
AnyModifiesPass::replace_any_modifiesrewrites thewrite_anymarker intowrite_any_slim/write_any_slice/write_any_strbased on the pointee type.write_any_slice<T>(slice: *mut [T])is generic over the element typeT, but the pass resolved it with the marker'sinstance_args, which hold the pointee type[T]. That producedwrite_any_slice::<[u8]>(*mut [[u8]]); itsfill_with(T::any)body then iterated&mut [[u8]], andinto_iterfailed to resolve because[u8]is neitherSizednorArbitrary.This path is only reached in replace mode (
stub_verified), which is whyproof_for_contractharnesses were unaffected and the existingmodifies_fat_pointertests (all check-mode) did not catch it — removing the#[kani::stub_verified]line from the reproducer avoids the crash.The fix resolves
write_any_slicewith the slice's element type instead of the pointee type.Resolved issues
Resolves #4748
Testing
tests/expected/function-contract/modifies_fat_pointer/slice_replace.rs, which exercises bothproof_for_contract(check) andstub_verified(replace) on a&mut [u8]slice-modifies contract — the replace harness reproduces the crash before this change.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.