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

analyze: memcpy/memset, void* rewrites, and other fixes for algo_md5 #1043

Merged
merged 28 commits into from
Nov 8, 2023

Conversation

spernsteiner
Copy link
Collaborator

  • 113c321...6c78399: Some refactorings and other small / self-contained changes
  • 01accdc...04fb24b: Rewriting pass to remove "HIR-only casts". These are casts like &x as *const T that don't get lowered to an actual MIR Rvalue::Cast assignment
  • 68a815c...4488b95: Fixes for several "unlower_map has no origin" errors in algo_md5
  • 8757538...40cc2e1: Implements rewrites to remove casts that don't change the pointee type
  • bc8a981: dataflow changes for memcpy/memset. Specifically, this detects whether the memcpy/memset is affecting exactly one item (byte count == mem::size_of::<T>(), where T is the pointee type) or possibly more than one item. Multi-item memcpy/memset requires the OFFSET permission on the input pointers. The check for mem::size_of::<T>() uses the new recent_writes analysis to find the instruction that was used to compute the byte length argument.
  • 251dd56...b274584: Reworks rewrite::expr::convert to fold certain rewrites together. Specifically, when applying a MIR rewrite and there is already a HIR rewrite on the current node, in some cases it will edit the current rewrite instead of wrapping it. For example, mir_op::RewriteKind::MutToImm applied to Rewrite::Ref(rw, Mutability::Mut) (&mut _) will produce Rewrite::Ref(rw, Mutability::Not) (&_) rather than Ref(Deref(Ref(rw, Mut)), Not) (&*(&mut _)). This fixes an issue with the removal of array .as_mut_ptr() calls in cases where we're rewriting the resulting pointer type to a non-mut slice.
  • 4592288...de532ab: Use pointee types when rewriting type annotations. This is the part that actually changes input: *mut c_void to input: &[u8] in certain algo_md5 function signatures.
  • f13ee41: Removes the CVoidCasts machinery, which is now superseded by pointee analysis and cast removal.
  • 6b2e491...caf059b: Implements rewriting of memcpy and memset to safe operations.
  • c09b2d6: Fixes some remaining rustc warnings.

mutbl: hir::Mutability,
) -> bool {
let adjusts = self.typeck_results.expr_adjustments(ex);
if adjusts.len() < 2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

a comment for the magic numbers would be helpful

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactored slightly in 6eca040 to make it clear we're inspecting the last two elements of adjusts.

ex.span, ref_expr.span, mutbl
);
// Check whether the `&x` / `&mut x` expr got the expected adjustments.
if self.expr_has_address_of_adjustments(ref_expr, mutbl) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is the part that extracts &x from the cast?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a small comment in 6eca040

@spernsteiner spernsteiner merged commit 2e4bcab into master Nov 8, 2023
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