Emit a diagnostic for a misapplied checked size/align intrinsic marker#4648
Open
MavenRain wants to merge 1 commit into
Open
Emit a diagnostic for a misapplied checked size/align intrinsic marker#4648MavenRain wants to merge 1 commit into
MavenRain wants to merge 1 commit into
Conversation
The `CheckedSizeOf` and `CheckedAlignOf` intrinsic generators assume the marked
function has the signature of the corresponding Kani intrinsic: a raw pointer
argument and an `Option<usize>` return. The `fn_marker` attribute is internal,
but nothing stops user code from attaching it to a function with a different
signature. When that happened, `build_some` unwrapped a missing `Some` variant
and the compiler panicked:
thread 'rustc' panicked at kani_intrinsics.rs:
called `Option::unwrap()` on a `None` value
Validate the signature before generating the body and emit a normal compiler
error when it does not match, following how other misapplied kani-internal
attributes are already reported.
Resolves model-checking#4589
Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
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
Fixes a compiler panic when the internal
CheckedSizeOfIntrinsic(orCheckedAlignOfIntrinsic)fn_markeris attached to a function whosesignature does not match the intrinsic.
Context
From the reproducer in #4589:
Kani panicked during codegen:
The
checked_size_of/checked_align_ofgenerators assume the markedfunction has the signature of the real intrinsic (a raw pointer argument and an
Option<usize>return), andbuild_some/build_nonelocate theSome/Nonevariants by looking for a variant with (or without) a field. Thefn_markerattribute is internal, but nothing stops user code from attachingit to a function returning some other type;
BadRethas no variant with afield, so
build_someunwrapped aNoneand the compiler panicked.Change
Validate the marked function's signature before generating the body. When it
is not a raw pointer argument with an
Option-shaped return, emit a normalcompiler error instead of panicking. This matches how Kani already reports
other misapplied kani-internal attributes. The valid intrinsic path is
unchanged.
Testing
Added
tests/ui/invalid-intrinsic-marker/, which runs the reproducer andchecks for the new diagnostic:
Verified it passes via
compiletest --suite ui --mode expected.Confirmed no regression to the real intrinsic path: the existing
tests/kani/SizeAndAlignOfDst/unsized_tail.rsstill verifies successfully(9/9 harnesses).
cargo check -p kani-compilerpasses and the file isrustfmt-clean.Resolves #4589
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.