-
Notifications
You must be signed in to change notification settings - Fork 97
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 copy
intrinsic
#1199
Audit for copy
intrinsic
#1199
Conversation
2369fe3
to
7a968ec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one question about whether we should check if length is zero before adding the checks.
/// size_of::<T>()` bytes (done by calls to `memmove`) | ||
/// In addition, we check that computing `count` in bytes (i.e., the third | ||
/// argument for the `memmove` call) would not overflow. | ||
fn codegen_copy_intrinsic( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functions are so much better!
|
||
// Generate alignment checks for both pointers | ||
let src_align = self.is_ptr_aligned(farg_types[0], src.clone()); | ||
let src_align_check = self.codegen_assert( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these checks relevant if length is zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please see the last sentence in "Safety" here: https://doc.rust-lang.org/std/intrinsics/fn.copy.html
Note that even if the effectively copied size
(count * size_of::<T>())
is 0, the pointers must be non-null and properly aligned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect! thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test coverage! Thanks
Description of changes:
Completes the audit for the
copy
intrinsic, which was disabled in #1081:src
anddst
.Initially, the changes in this PR were for both
copy
andcopy_nonoverlapping
, but as it has been noted in #1176 thecopy_nonoverlapping
case is handled somewhere else.Resolved issues:
Creates #1198
Part of #1163
Call-outs:
Testing:
How is this change tested? Existing regression and 7 new/restored tests.
Is this a refactor change? No.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.