Skip to content

Basic tests for size_of_val and min_alig_of_val#1101

Merged
adpaco-aws merged 5 commits intomodel-checking:mainfrom
adpaco-aws:size-align-val-tests
Apr 27, 2022
Merged

Basic tests for size_of_val and min_alig_of_val#1101
adpaco-aws merged 5 commits intomodel-checking:mainfrom
adpaco-aws:size-align-val-tests

Conversation

@adpaco-aws
Copy link
Contributor

Description of changes:

Adds two tests for size_of_val and min_align_of_val.

@celinval added tests for dynamically-sized types in #1089 , these ones just complement them by testing basic types.

Resolved issues:

Part of #727

Call-outs:

Testing:

  • How is this change tested? Adds two tests.

  • Is this a refactor change? No.

Checklist

  • Each commit message has a non-empty body, explaining why the change was made
  • Methods or procedures are documented
  • Regression or unit tests are included, or existing tests cover the modified code
  • My PR is restricted to a single feature or bugfix

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 April 23, 2022 20:36
enum MyEnum {
Variant,
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be interesting to add a repr(C) struct which would require padding and make sure we get this right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a repr(C) struct and assertions based on it. As far as I can tell, it's working as expected:

  • Size takes into account padding
  • Alignment is the max alignment for each field
    But let me know if you want to test specific cases and I will add them.

// SPDX-License-Identifier: Apache-2.0 OR MIT

// Check that we get the expected results for the `min_align_of_val` intrinsic
// with common data types
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this architecture specific, of do these min aligns come from the rust spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that min_align_of_val depends on min_global_align, which is an architecture option.
Please note that in #1054 we added checks to ensure that min_global_align is unspecified or equal to 1, otherwise Kani will stop there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment that the tests here assume x86, otherwise good to go.

Copy link
Contributor

@danielsn danielsn left a comment

Choose a reason for hiding this comment

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

Approved modulo one comment

// SPDX-License-Identifier: Apache-2.0 OR MIT

// Check that we get the expected results for the `min_align_of_val` intrinsic
// with common data types
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment that the tests here assume x86, otherwise good to go.

@adpaco-aws adpaco-aws merged commit f7a9a59 into model-checking:main Apr 27, 2022
@adpaco-aws adpaco-aws mentioned this pull request Apr 27, 2022
tedinski pushed a commit that referenced this pull request Apr 27, 2022
* Basic tests for `size_of_val` and `min_alig_of_val`

* Fix format

* Add cases for `repr(C)` struct

* Add note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants