Skip to content

Fix -Z uninit-checks panic on zero-sized primitive layouts - #4899

Merged
feliperodri merged 1 commit into
model-checking:mainfrom
tautschnig:fix-uninit-zero-sized-primitive
Sep 30, 2026
Merged

feliperodri merged 1 commit into
model-checking:mainfrom
tautschnig:fix-uninit-zero-sized-primitive

Conversation

@tautschnig

Copy link
Copy Markdown
Member

Computing the data bytes of a type for -Z uninit-checks 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.

The regression test tests/expected/uninit/uninhabited-union-field uses 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.

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]>
Copilot AI lite review requested due to automatic review settings September 28, 2026 15:25
@tautschnig
tautschnig requested review from a team as code owners September 28, 2026 15:25
@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Sep 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
feliperodri added this pull request to the merge queue Sep 30, 2026
Merged via the queue into model-checking:main with commit 63b672c Sep 30, 2026
41 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic: uninit checks: FieldsShape::Primitive with a different ABI than ValueAbi::Scalar

3 participants