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

Fix issue with value_of / align_of traits #1089

Merged
merged 5 commits into from
Apr 22, 2022

Conversation

celinval
Copy link
Contributor

@celinval celinval commented Apr 21, 2022

Description of changes:

We were trying to figure out the values of those properties during runtime, which is not possible. Fix the code to look for the information in the vtable instead.

Resolved issues:

Fixes #1074

Call-outs:

This is v2. The initial PR was trying to mitigate it but it turned out that the fix was straight forward.

Testing:

  • How is this change tested? New 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.

We were trying to figure out the values of those properties during
runtime, which is not possible. Emit a runtime error for now.
@celinval celinval requested a review from a team as a code owner April 21, 2022 17:58
@@ -294,7 +294,17 @@ impl<'tcx> GotocCtx<'tcx> {
let tp_ty = instance.substs.type_at(0);
let arg = fargs.remove(0);
let size_align = self.size_and_align_of_dst(tp_ty, arg);
self.codegen_expr_to_place(p, size_align.$which)
if size_align.is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

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

if let Some instead of using unwrap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because this can be None.

// https://github.com/model-checking/kani/issues/1074
// The size of dyn T is only known at runtime. Thus, we need to retrieve that
// information from the object vtable.
None
Copy link
Contributor

Choose a reason for hiding this comment

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

Does arg.member("vtable").member("size") not work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably. I just didn't have time to go figure it out. Let me try and maybe we can just fix this issue. :)

@@ -1004,7 +1013,7 @@ impl<'tcx> GotocCtx<'tcx> {
// Call this function recursively to compute the size and align for the last field.
let field_ty = layout.field(self, n).ty;
let SizeAlign { size: unsized_size, align: mut unsized_align } =
self.size_and_align_of_dst(field_ty, arg);
self.size_and_align_of_dst(field_ty, arg.clone())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this clone now needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was probably some debug I removed and forgot to revert this. I'll remove it.

fn check_align_simple() {
let a = A { id: 0 };
let t: &dyn T = &a;
assert_eq!(align_of_val(t), 8);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this assume a particular architecture?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should hold for the architecture we currently support.

@celinval celinval changed the title Mitigation for issue with value_of / align_of traits Fix issue with value_of / align_of traits Apr 21, 2022
@celinval celinval merged commit 8e7b99f into model-checking:main Apr 22, 2022
tedinski pushed a commit to tedinski/rmc that referenced this pull request Apr 22, 2022
We were trying to figure out the values of those properties during runtime, which is not possible. Fix the code to look for the information in the vtable instead.
tedinski pushed a commit to tedinski/rmc that referenced this pull request Apr 25, 2022
We were trying to figure out the values of those properties during runtime, which is not possible. Fix the code to look for the information in the vtable instead.
tedinski pushed a commit to tedinski/rmc that referenced this pull request Apr 26, 2022
We were trying to figure out the values of those properties during runtime, which is not possible. Fix the code to look for the information in the vtable instead.
@adpaco-aws adpaco-aws mentioned this pull request Apr 27, 2022
tedinski pushed a commit that referenced this pull request Apr 27, 2022
We were trying to figure out the values of those properties during runtime, which is not possible. Fix the code to look for the information in the vtable instead.
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.

Kani implementations of mem::size_of_val and mem::align_of_val are incorrect for traits
3 participants