Repository navigation
Fix -Z uninit-checks panic on zero-sized primitive layouts - #4899
Merged
feliperodri merged 1 commit intoSep 30, 2026
Merged
Conversation
Resolves model-checking#4855 Computing the data bytes of a type assumed that every `FieldsShape::Primitive` layout has a scalar ABI, and panicked ("FieldsShape::Primitive with a different ABI than ValueRepr::Scalar") otherwise. The never type `!` and other uninhabited types have a zero-sized primitive layout with an aggregate ABI, so instrumenting a union with an uninhabited field, or a place of type `!`, crashed the compiler. A zero-sized primitive has no bytes whose initialization could be tracked: return no data bytes for it. Add a regression test that also checks, as a negative control, that reading uninitialized bytes of such a union is still reported. Co-authored-by: Kiro <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved issues were identified.
Review effort: Lite
Findings: None
What changed in this PR
Fixes -Z uninit-checks crashes for zero-sized primitive layouts, especially uninhabited types.
Changes:
- Skip data-byte tracking for zero-sized primitive layouts.
- Add regression coverage for uninhabited union fields and uninitialized reads.
- Record expected verification results.
| File | Description |
|---|---|
tests/expected/uninit/uninhabited-union-field/uninhabited-union-field.rs |
Adds regression harnesses. |
tests/expected/uninit/uninhabited-union-field/expected |
Records expected verification outcomes. |
kani-compiler/src/kani_middle/transform/check_uninit/ty_layout.rs |
Handles zero-sized primitive layouts safely. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
feliperodri
approved these changes
Sep 30, 2026
feliperodri
enabled auto-merge
September 30, 2026 00:35
Merged
via the queue into
model-checking:main
with commit Sep 30, 2026
63b672c
41 of 42 checks passed
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.
Computing the data bytes of a type for
-Z uninit-checksassumed that everyFieldsShape::Primitivelayout has a scalar ABI, and panicked ("FieldsShape::Primitive with a different ABI than ValueRepr::Scalar") otherwise. The never type!and other uninhabited types have a zero-sized primitive layout with an aggregate ABI, so instrumenting a union with an uninhabited field, or a place of type!, crashed the compiler. A zero-sized primitive has no bytes whose initialization could be tracked: return no data bytes for it.The regression test
tests/expected/uninit/uninhabited-union-fielduses the reproducer from the issue and also checks, as a negative control, that reading uninitialized bytes of such a union is still reported. It crashes the compiler without the fix.Resolves #4855
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.