Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid mismatch when generating structs that represent scalar data but also include ZSTs #2794

Merged
merged 15 commits into from
Sep 29, 2023

Conversation

adpaco-aws
Copy link
Contributor

@adpaco-aws adpaco-aws commented Sep 28, 2023

Description of changes:

This PR considers another case for the code generation of scalar data. In particular, when the expected type is an ADT, we previously considered two cases: either there is no field or there is one. But in cases where the ADT includes a ZST, the ADT will contain multiple fields: one associated to the scalar data, and other fields associated to the ZSTs. In those cases, we ended up crashing as in #2680:

error: internal compiler error: Kani unexpectedly panicked at panicked at cprover_bindings/src/goto_program/expr.rs:804:9:
                                assertion failed: `(left == right)`
                                  left: `2`,
                                 right: `1`: Error in struct_expr; mismatch in number of fields and values.
                                    StructTag("tag-_161424092592971241517604180463813633314")
                                    [Expr { value: IntConstant(0), typ: Unsignedbv { width: 8 }, location: None, size_of_annotation: None }].

thread 'rustc' panicked at cprover_bindings/src/goto_program/expr.rs:804:9:
assertion failed: `(left == right)`
  left: `2`,
 right: `1`: Error in struct_expr; mismatch in number of fields and values.
	StructTag("tag-_161424092592971241517604180463813633314")
	[Expr { value: IntConstant(0), typ: Unsignedbv { width: 8 }, location: None, size_of_annotation: None }]

With the changes in this PR, that's no longer the case.

Resolves #2364
Resolves #2680

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

@adpaco-aws adpaco-aws requested a review from a team as a code owner September 28, 2023 20:14
@github-actions github-actions bot added the Z-BenchCI Tag a PR to run benchmark CI label Sep 28, 2023
Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

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

I'm worried this fix is too specific to PhantomData. Instead, we want something that will work for any struct with multiple fields where only one is not ZST.

kani-compiler/src/codegen_cprover_gotoc/codegen/operand.rs Outdated Show resolved Hide resolved
kani-compiler/src/codegen_cprover_gotoc/codegen/operand.rs Outdated Show resolved Hide resolved
tests/cargo-kani/phantom-data/src/lib.rs Outdated Show resolved Hide resolved
kani-compiler/src/codegen_cprover_gotoc/codegen/operand.rs Outdated Show resolved Hide resolved
@adpaco-aws adpaco-aws changed the title Avoid mismatch when generating structs that represent scalar data but also include phantom data Avoid mismatch when generating structs that represent scalar data but also include ZSTs Sep 28, 2023
Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks @adpaco-aws

@adpaco-aws adpaco-aws merged commit a20437a into model-checking:main Sep 29, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-BenchCI Tag a PR to run benchmark CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: mismatch in number of fields and values. Kani panics during Goto translation for code using bitvec
3 participants