Codegen single-non-ZST-field constants with name-keyed struct fields - #4724
Merged
feliperodri merged 2 commits intoAug 14, 2026
Merged
Conversation
try_codegen_constant built the field-value list in declaration order and used the positional struct constructor, but the goto struct type lists fields in LAYOUT order. For constants whose layout reorders fields (e.g. a (Wrap(u8), u16) pair placing the u16 first), this ICEd with 'value type does not match field type' (surfaced by yansi and bitvec in a crates.io autoharness sweep). Key the values by the variant's field names instead. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an ICE in try_codegen_constant when codegenning struct constants whose field layout order differs from declaration order by switching from positional struct initialization to name-keyed field initialization, aligning with the goto struct’s layout-based field ordering.
Changes:
- Build struct constant initializers as a name-keyed map of field values and use
Expr::struct_exprinstead ofstruct_expr_from_values. - Add a regression test intended to cover layout-vs-declaration field order mismatches in constant struct codegen.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| kani-compiler/src/codegen_cprover_gotoc/codegen/operand.rs | Switch constant struct expansion to name-keyed field initialization to match goto struct layout order. |
| tests/kani/Structs/const_struct_layout_order.rs | Add regression test for struct-constant codegen with layout-reordered fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The `try_codegen_constant` fix only applies to constant structs with a single non-ZST field (`non_zst_types.len() == 1`). The original test used a `Pair` with two non-ZST fields (`Wrap(u8)` and `u16`), which takes the separate allocation branch and never reaches the name-keyed `struct_expr` path, so it did not cover the regression. Replace it with a struct that has exactly one non-ZST field: a zero-sized `Marker` declared before a higher-aligned `u64`, so layout order (`u64` first) differs from declaration order. Verified that this reproduces the "value type does not match field type" ICE on the pre-fix compiler and passes with the fix. Signed-off-by: Felipe Monteiro <felisous@amazon.com>
feliperodri
approved these changes
Aug 14, 2026
feliperodri
enabled auto-merge
August 14, 2026 00:50
Merged
via the queue into
model-checking:main
with commit Aug 14, 2026
2bf550f
33 of 34 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.
try_codegen_constantbuilt the field-value list in declaration order and used the positional struct constructor, but the goto struct type lists fields in layout order. For constants whose layout reorders fields (e.g. a(Wrap(u8), u16)pair placing theu16first), this ICEd with value type does not match field type.Surfaced by yansi and bitvec in a top-500 crates.io autoharness sweep (tracking #3832); the fix and regression test are independent of autoharness.
Changes
struct_expr) instead of position (struct_expr_from_values).By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.