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

Audit for write_bytes #1102

Merged
merged 8 commits into from
Apr 26, 2022
Merged

Conversation

adpaco-aws
Copy link
Contributor

Description of changes:

Moves and updates the write_bytes intrinsic implementation with an alignment check that it was missing. Adds 3 tests cases (2 of them in expected).

Resolved issues:

Part of #727

Call-outs:

Testing:

  • How is this change tested? Adds 3 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 21:51
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.

Looks good, a couple comments

align,
PropertyClass::DefaultAssertion,
"`dst` is properly aligned",
loc.clone(),
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to clone locations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed!

);
let layout = self.layout_of(ty);
let sz = Expr::int_constant(layout.size.bytes(), Type::size_t());
let memset_call = BuiltinFn::Memset.call(vec![dst, val, count.mul(sz)], loc);
Copy link
Contributor

Choose a reason for hiding this comment

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

We have overflow checking on, right? So we'll see if this overflows?

Copy link
Contributor Author

@adpaco-aws adpaco-aws Apr 26, 2022

Choose a reason for hiding this comment

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

I checked it but we were not detecting overflows here. Updated to include an explicit overflow check for this computation. Added another test to check overflows.

@@ -1156,4 +1149,34 @@ impl<'tcx> GotocCtx<'tcx> {
let expr = dst.dereference().assign(src, loc.clone());
Stmt::block(vec![align_check, expr], loc)
}

/// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to `val`
Copy link
Contributor

Choose a reason for hiding this comment

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

Like the callout to the documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😄

@adpaco-aws adpaco-aws requested a review from danielsn April 26, 2022 15:58
Comment on lines +1182 to +1191
// Check that computing `bytes` would not overflow
let layout = self.layout_of(ty);
let size = Expr::int_constant(layout.size.bytes(), Type::size_t());
let bytes = count.mul_overflow(size);
let overflow_check = self.codegen_assert(
bytes.overflowed.not(),
PropertyClass::ArithmeticOverflow,
format!("{}: attempt to compute `bytes` which would overflow", intrinsic).as_str(),
loc,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this PR, but we've done this check > 1 times, which means a helper fn might be good

@adpaco-aws adpaco-aws merged commit 0ade24d into model-checking:main Apr 26, 2022
@adpaco-aws adpaco-aws mentioned this pull request Apr 27, 2022
tedinski pushed a commit that referenced this pull request Apr 27, 2022
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