Autoharness: support &CStr arguments under --bounded-arguments - #4804
Open
srivatsansamraj wants to merge 2 commits into
Open
srivatsansamraj wants to merge 2 commits into
srivatsansamraj wants to merge 2 commits into
Conversation
`&str` arguments are generated by `any_str_ref`, which returns the longest valid-UTF-8 prefix of nondeterministic harness-local storage. `&CStr` had no such model and was skipped for a missing Arbitrary implementation: 67 functions on a whole-library `verify-std` run, 23 of them in `core`. Add `any_c_str_ref` with the same discipline. The last byte of the storage is set to NUL and `from_bytes_until_nul` returns the bytes before the first one, so the result is a deterministic function of the nondeterministic bytes and satisfies `CStr`'s invariant by construction: no `assume` is involved, and every C string of length `k` below the bound arises from storage whose first NUL is at index `k`. The slice bound applies, less one byte for the NUL. Eligibility and harness generation both identify `CStr` through `is_c_str`, so they cannot disagree. `&mut CStr` stays unsupported, as `&mut str` does. The test follows `cargo_autoharness_slices`: the argument is reported as requiring the flag without it, and with it a bounds-checked read fails on the empty string, the no-interior-NUL invariant holds, and covers show the empty, the longest and a specific C string are all generated.
This was referenced Sep 18, 2026
The local receiving the `any_c_str_ref` call was typed `&mut CStr`, the shape the slice model returns, while the model returns `&CStr`; the value was then reborrowed as shared. Codegen tolerated the mismatch, but the MIR was ill-typed. Only the slice model returns `&mut [T]`, to serve both mutabilities; the string models return the shared reference. The destination now follows that, and the reborrow applies to slices only.
Contributor
Author
|
The perf-benchcomp failure is |
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.
&strarguments are generated byany_str_ref, which returns the longest valid-UTF-8 prefix of nondeterministic harness-local storage.&CStrhad no model and was skipped for a missing Arbitrary implementation: 67 functions on a whole-libraryverify-stdrun, 23 of them incore(CStr::to_bytes,to_str,count_bytes, thePartialEq/Ordimpls, and so on).any_c_str_reffollows the same discipline. The last byte of the storage is set to NUL andfrom_bytes_until_nulreturns the bytes before the first one, so the result is a deterministic function of the nondeterministic bytes and satisfiesCStr's invariant by construction: noassume, and every C string of lengthkbelow the bound arises from storage whose first NUL is at indexk. The slice bound applies, less one byte for the NUL. Eligibility and harness generation both go throughis_c_str, so they cannot disagree.&mut CStrstays unsupported, as&mut strdoes.any_c_str_refinkani_core,KaniModel::AnyCStrRef, theRefarm inautoharness_supported_arg_tyand the matching case incall_kani_any_for_ty.cargo_autoharness_c_str, in the shape ofcargo_autoharness_slices: reported as requiring the flag without it; with it, a bounds-checked read fails on the empty string, the no-interior-NUL invariant holds, and covers show the empty, the longest and a specific C string are all generated.Resolves #4803
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.