Fix ICE on non-literal cover/assert/check message expressions - #4711
Open
ivmat wants to merge 1 commit into
Open
Fix ICE on non-literal cover/assert/check message expressions#4711ivmat wants to merge 1 commit into
cover/assert/check message expressions#4711ivmat wants to merge 1 commit into
Conversation
`kani-compiler`'s codegen hooks for `kani::cover`, `kani::assert`, `kani::check` and the internal safety-check/unsupported-check hooks all called `gcx.extract_const_message(&msg).unwrap()` to recover the message string. `extract_const_message` returns `None` whenever the message operand does not codegen down to a string-literal constant -- for example when it is a function parameter -- which turned the `.unwrap()` into an internal compiler error instead of a normal diagnostic. Add `extract_msg_or_err`, mirroring the existing `utils::span_err` + `abort_if_errors` pattern already used by neighbouring intrinsic codegen in this file, and use it at all six call sites in `hooks.rs` (Cover, Assert, UnsupportedCheck, SafetyCheck, SafetyCheckNoAssume, Check). Each now emits a spanned "`<construct>` message must be a string literal" error and aborts compilation cleanly instead of panicking. Add UI regression tests for the two publicly reachable constructs, `kani::cover` and `kani::assert`, modelled on the existing `tests/ui/ice-size-overflow` test. `kani::check` is `pub(crate)` with no public re-export, so user code cannot invoke it directly.
ivmat
force-pushed
the
fix-ice-non-literal-message
branch
from
August 3, 2026 23:34
72f4f5a to
4fa8466
Compare
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.
Problem
kani-compiler's codegen hooks forkani::cover,kani::assert,kani::checkand the internalsafety-check/unsupported-check hooks all call
gcx.extract_const_message(&msg).unwrap()to recover themessage string.
extract_const_messagereturnsNonewhenever the message operand does not codegen down to astring-literal constant — for example when it is a function parameter — so the
.unwrap()produces aninternal compiler error rather than a normal diagnostic.
Reproducer (
kani::covercase):This still reproduces on
main: all sixextract_const_message(&msg).unwrap()call sites are presentin
kani-compiler/src/codegen_cprover_gotoc/overrides/hooks.rs.Fix
Add
extract_msg_or_err, which mirrors the existingutils::span_err+abort_if_errorspatternalready used by neighbouring intrinsic codegen in the same file, and use it at all six call sites
(
Cover,Assert,UnsupportedCheck,SafetyCheck,SafetyCheckNoAssume,Check).Each now emits a spanned
`<construct>` message must be a string literalerror and abortscompilation cleanly instead of panicking.
Tests
UI regression tests modelled on the existing
tests/ui/ice-size-overflowtest (a prior"ICE → clean error" regression test):
tests/ui/cover-non-literal-message/tests/ui/assert-non-literal-message/kani::checkispub(crate)inlibrary/kani_core/src/lib.rswith no public re-export, so user codecannot invoke it directly (it fails earlier with
E0425). The remaining hooks(
safety_check,safety_check_no_assume,unsupported_check) are compiler-generated and notreachable from user code either, so neither is given a UI test.
Testing performed, and what was not run
cargo build -p kani-compileron this branch — passes.comparing output against
expectedthe same waycompiletest'sverify_outputdoes.Stated plainly rather than left to be assumed:
compiletestitself was not run. It invokes a binary namedkaniresolved throughPATH, whichin a source checkout is the
kani-verifierproxy resolving${KANI_HOME}, not the local build.Wiring that up would have meant installing over the machine's global Kani install.
would have mutated the pin.
Happy to adjust the diagnostic wording or the test placement if you'd prefer something different.