Skip to content

Give the x87_f80_raw lang item its rustc size - #5197

Merged
feliperodri merged 4 commits into
model-checking:mainfrom
feliperodri:fix-x87-f80-layout
Nov 19, 2026
Merged

feliperodri merged 4 commits into
model-checking:mainfrom
feliperodri:fix-x87-f80-layout

Conversation

@feliperodri

Copy link
Copy Markdown
Member

Kani can't compile core on nightly-2026-11-12. That blocks verify-std and the verify-rust-std toolchain sync (model-checking/verify-rust-std#766), whose Kani List, autoharness and metrics jobs all abort in codegen.

The nightly added the x87_f80_raw lang item, a struct with no fields that rustc lays out as an 80-bit x87 float (10 bytes). Kani built its type from the fields, so it had 0 bits, and the x87_f80 wrapper came out 48 bits wide instead of 128. Every transmute between x87_f80 and MaybeUninit<x87_f80> in core then hit the size assertion in transmute_to.

The fix gives a field-less struct with a non-zero layout size a single padding component of that size. A second crash showed up once the first was gone: building x87_f80_raw {} (autoharness does this through kani::any) indexed operand 0 of an empty list, because rustc reports one pseudo-field for a primitive layout. That value is now built from padding alone.

Where I'd like input: the padding-only representation keeps the bits nondeterministic, which is right as long as Kani has no x87 float semantics. If we'd rather model it as an 80-bit float type in CBMC, that's a bigger change, and I'd do it separately.

Testing:

  • tests/kani/Structs/x87_f80_layout.rs checks the wrapper's size and round-trips bytes through the same transmutes core does. Without the fix it reproduces the panic from Codegen ICE on x87_f80 (nightly-2026-11-12): transmute_to size mismatch 128 vs 48 bits #5191.
  • The full kani compiletest suite passes (657 passed, 0 failed).
  • kani list --with-autoharness on verify-rust-std#766 now completes (it aborted in codegen before). The second fix has no regression test of its own: only core can construct x87_f80_raw, so that path is covered by verify-std runs.

Resolves #5191

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

nightly-2026-11-12 added the `x87_f80_raw` lang item, a struct with no
fields that rustc lays out as an 80-bit x87 float (10 bytes). Kani built
its type from the fields, so it got 0 bits, and the `x87_f80` wrapper
came out 48 bits wide instead of 128. Every transmute to or from
`x87_f80` in `core` then failed the size assertion in `transmute_to`.

Represent a field-less struct with a non-zero layout size as padding of
that size. Building such a value (`x87_f80_raw {}`, which autoharness
does through `kani::any`) also indexed operand 0 of an empty list,
because rustc reports one pseudo-field for a primitive layout; build it
from padding alone instead.

Resolves model-checking#5191
@feliperodri
feliperodri requested review from a team as code owners November 18, 2026 20:57
@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 Nov 18, 2026
@feliperodri
feliperodri requested a balanced review from Copilot November 18, 2026 21:05
@feliperodri feliperodri added [C] Internal Tracks some internal work. I.e.: Users should not be affected. Z-Kani Compiler Issues that require some changes to the compiler labels Nov 18, 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.

🟡 Changes recommended

The x87_f80 layout test treats six padding bytes as initialized and preserved across a transmute, relying on behavior Rust does not guarantee; it should use MaybeUninit bytes and compare only the ten payload bytes.

1 open issue
What changed in this PR

This PR addresses #5191 by giving x87_f80_raw its rustc-defined size in Kani’s code generation, unblocking standard-library verification on the newer nightly.

Changes:

  • Represent fieldless structs with nonzero layout size using padding.
  • Handle empty aggregate operands without indexing rustc’s pseudo-field.
  • Add x86_64 regression harnesses for x87_f80 size and transmutes.
File Description
tests/​kani/​Structs/​x87_f80_layout.rs Adds layout and transmute regression coverage.
kani-compiler/​src/​codegen_cprover_gotoc/​codegen/​typ.rs Preserves rustc-defined sizes for fieldless structs.
kani-compiler/​src/​codegen_cprover_gotoc/​codegen/​rvalue.rs Constructs padding-only aggregates without accessing missing operands.

Review effort: Balanced

Comment thread tests/kani/Structs/x87_f80_layout.rs Resolved
A typed copy of x87_f80 need not preserve its six padding bytes, so read
the bytes back as MaybeUninit<u8> and compare the ten float bytes.

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.

🟢 Approval recommended

No active review issues remain for the fieldless-struct layout and empty-aggregate fixes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@rajath-mk rajath-mk 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.

Looks good. The x86 regression job on this head passes the new layout test (on aarch64 it's the empty harness, so I relied on CI for that), and a repr(align) unit struct still has size 0 under Kani, so the size != 0 guard keeps ordinary unit structs on the old path. Approving

@feliperodri
feliperodri added this pull request to the merge queue Nov 19, 2026
Merged via the queue into model-checking:main with commit b896cff Nov 19, 2026
34 checks passed
@feliperodri
feliperodri deleted the fix-x87-f80-layout branch November 19, 2026 19:52
feliperodri added a commit to model-checking/verify-rust-std that referenced this pull request Nov 20, 2026
Kani faffcee3 gave the field-less x87_f80_raw lang item 0 bits, so
codegen of core aborted on every transmute involving x87_f80
(model-checking/kani#5191), which broke Kani List, autoharness and
Kani Metrics.

53cb531 is the fix from model-checking/kani#5197 on top of faffcee3, so
it stays on nightly-2026-11-12. The merged commit (b896cff) is on
nightly-2026-11-18; move to a commit on Kani main at the next sync.

The ESBMC job runs without Kani's reachability checks (21bd541) until
ESBMC can read them: esbmc/esbmc#10875.
v3risec pushed a commit to v3risec/verify-rust-std that referenced this pull request Nov 21, 2026
…#766)

This is an automated PR to merge library subtree updates from 2026-10-23
(rust-lang/rust@7189d39) to 2026-11-12
(rust-lang/rust@3ef0c22) (inclusive)
into main. `git merge` resulted in conflicts, which require manual
resolution. Files were commited with merge conflict markers. **Do not
remove or edit the following annotations:**
git-subtree-dir: library
git-subtree-split: 5a2d852

---
Kani is pinned to `53cb531`: the x87_f80 fix (model-checking/kani#5197)
on top of `faffcee3`, kept on nightly-2026-11-12. The ESBMC job runs
without Kani's reachability checks until esbmc/esbmc#10875 is resolved.

---------

Signed-off-by: hashcatHitman <[email protected]>
Signed-off-by: Hardik Kumar <[email protected]>
Signed-off-by: Ayush Singh <[email protected]>
Co-authored-by: Yash Aggarwal <[email protected]>
Co-authored-by: Caleb Zulawski <[email protected]>
Co-authored-by: The rustc-josh-sync Cronjob Bot <[email protected]>
Co-authored-by: Jacob Pratt <[email protected]>
Co-authored-by: Web4everyone32 <[email protected]>
Co-authored-by: panstromek <[email protected]>
Co-authored-by: Ralf Jung <[email protected]>
Co-authored-by: bors <[email protected]>
Co-authored-by: Mend Renovate <[email protected]>
Co-authored-by: Jonathan Brouwer <[email protected]>
Co-authored-by: arvindkhoisnam <[email protected]>
Co-authored-by: Mikolaj Wielgus <[email protected]>
Co-authored-by: Trevor Gross <[email protected]>
Co-authored-by: Hugo Sanz González <[email protected]>
Co-authored-by: hashcatHitman <[email protected]>
Co-authored-by: Yilin Chen <[email protected]>
Co-authored-by: Guillaume Gomez <[email protected]>
Co-authored-by: Thalia Archibald <[email protected]>
Co-authored-by: bjorn3 <[email protected]>
Co-authored-by: Nag <[email protected]>
Co-authored-by: Max Dexheimer <[email protected]>
Co-authored-by: asquared31415 <[email protected]>
Co-authored-by: Chris Denton <[email protected]>
Co-authored-by: The Miri Cronjob Bot <[email protected]>
Co-authored-by: Frank King <[email protected]>
Co-authored-by: Jules Bertholet <[email protected]>
Co-authored-by: malezjaa <[email protected]>
Co-authored-by: Alan Wu <[email protected]>
Co-authored-by: Michael Howell <[email protected]>
Co-authored-by: Voxell Paladynee <[email protected]>
Co-authored-by: xtqqczze <[email protected]>
Co-authored-by: Mahdi Ali-Raihan <[email protected]>
Co-authored-by: Daniel Scherzer <[email protected]>
Co-authored-by: Valaphee64.exe <[email protected]>
Co-authored-by: Jakub Beránek <[email protected]>
Co-authored-by: Folkert de Vries <[email protected]>
Co-authored-by: Tim (Theemathas Chirananthavat) <[email protected]>
Co-authored-by: Xing Xue <[email protected]>
Co-authored-by: mejrs <[email protected]>
Co-authored-by: Jana Dönszelmann <[email protected]>
Co-authored-by: León Orell Valerian Liehr <[email protected]>
Co-authored-by: Joy <[email protected]>
Co-authored-by: Zac Harrold <[email protected]>
Co-authored-by: Marius Melzer <[email protected]>
Co-authored-by: krokodeyu <[email protected]>
Co-authored-by: Beat Küng <[email protected]>
Co-authored-by: yhx-12243 <[email protected]>
Co-authored-by: waffle <[email protected]>
Co-authored-by: Toni Peter <[email protected]>
Co-authored-by: Zalathar <[email protected]>
Co-authored-by: zannabianca1997 <[email protected]>
Co-authored-by: Hardik Kumar <[email protected]>
Co-authored-by: lazerg <[email protected]>
Co-authored-by: Ayush Singh <[email protected]>
Co-authored-by: Lewis McClelland <[email protected]>
Co-authored-by: Dennis Duda <[email protected]>
Co-authored-by: Nicole LeGare <[email protected]>
Co-authored-by: Pavel Grigorenko <[email protected]>
Co-authored-by: Shun Sakai <[email protected]>
Co-authored-by: Stefan Lankes <[email protected]>
Co-authored-by: Vlad Mashkautsan <[email protected]>
Co-authored-by: Joseph Zhao <[email protected]>
Co-authored-by: Joseph Zhao <[email protected]>
Co-authored-by: gitbot <git@bot>
Co-authored-by: Felipe R. Monteiro <[email protected]>
Co-authored-by: Lucas C. Cordeiro <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[C] Internal Tracks some internal work. I.e.: Users should not be affected. Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-Kani Compiler Issues that require some changes to the compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codegen ICE on x87_f80 (nightly-2026-11-12): transmute_to size mismatch 128 vs 48 bits

3 participants