]> git.lizzy.rs Git - rust.git/blobdiff - src/shims/mod.rs
Auto merge of #2189 - RalfJung:clippy, r=RalfJung
[rust.git] / src / shims / mod.rs
index 90dcc4d8ff1e4d35f4e737b2b42b9381b401eedb..926fcd5d040b8b35ec061b31cda253b3f83971de 100644 (file)
@@ -16,6 +16,7 @@
 use log::trace;
 
 use rustc_middle::{mir, ty};
+use rustc_target::spec::abi::Abi;
 
 use crate::*;
 use helpers::check_arg_count;
@@ -25,17 +26,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
     fn find_mir_or_eval_fn(
         &mut self,
         instance: ty::Instance<'tcx>,
+        abi: Abi,
         args: &[OpTy<'tcx, Tag>],
-        ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
-        unwind: Option<mir::BasicBlock>,
-    ) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
+        unwind: StackPopUnwind,
+    ) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> {
         let this = self.eval_context_mut();
-        trace!("eval_fn_call: {:#?}, {:?}", instance, ret.map(|p| *p.0));
+        trace!("eval_fn_call: {:#?}, {:?}", instance, dest);
 
         // There are some more lang items we want to hook that CTFE does not hook (yet).
         if this.tcx.lang_items().align_offset_fn() == Some(instance.def.def_id()) {
-            let &[ptr, align] = check_arg_count(args)?;
-            if this.align_offset(ptr, align, ret, unwind)? {
+            let [ptr, align] = check_arg_count(args)?;
+            if this.align_offset(ptr, align, dest, ret, unwind)? {
                 return Ok(None);
             }
         }
@@ -48,32 +51,32 @@ fn find_mir_or_eval_fn(
             // to run extra MIR), and Ok(Some(body)) if we found MIR to run for the
             // foreign function
             // Any needed call to `goto_block` will be performed by `emulate_foreign_item`.
-            return this.emulate_foreign_item(instance.def_id(), args, ret, unwind);
+            return this.emulate_foreign_item(instance.def_id(), abi, args, dest, ret, unwind);
         }
 
         // Otherwise, load the MIR.
-        Ok(Some(&*this.load_mir(instance.def, None)?))
+        Ok(Some((&*this.load_mir(instance.def, None)?, instance)))
     }
 
     /// Returns `true` if the computation was performed, and `false` if we should just evaluate
     /// the actual MIR of `align_offset`.
     fn align_offset(
         &mut self,
-        ptr_op: OpTy<'tcx, Tag>,
-        align_op: OpTy<'tcx, Tag>,
-        ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
-        unwind: Option<mir::BasicBlock>,
+        ptr_op: &OpTy<'tcx, Tag>,
+        align_op: &OpTy<'tcx, Tag>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
+        unwind: StackPopUnwind,
     ) -> InterpResult<'tcx, bool> {
         let this = self.eval_context_mut();
-        let (dest, ret) = ret.unwrap();
+        let ret = ret.unwrap();
 
-        if this.memory.extra.check_alignment != AlignmentCheck::Symbolic {
+        if this.machine.check_alignment != AlignmentCheck::Symbolic {
             // Just use actual implementation.
             return Ok(false);
         }
 
-        let req_align = this
-            .force_bits(this.read_scalar(align_op)?.check_init()?, this.pointer_size())?;
+        let req_align = this.read_scalar(align_op)?.to_machine_usize(this)?;
 
         // Stop if the alignment is not a power of two.
         if !req_align.is_power_of_two() {
@@ -81,13 +84,11 @@ fn align_offset(
             return Ok(true); // nothing left to do
         }
 
-        let ptr_scalar = this.read_scalar(ptr_op)?.check_init()?;
-
-        if let Ok(ptr) = this.force_ptr(ptr_scalar) {
+        let ptr = this.read_pointer(ptr_op)?;
+        if let Ok((alloc_id, _offset, _)) = this.ptr_try_get_alloc_id(ptr) {
             // Only do anything if we can identify the allocation this goes to.
-            let cur_align =
-                this.memory.get_size_and_align(ptr.alloc_id, AllocCheck::MaybeDead)?.1.bytes();
-            if u128::from(cur_align) >= req_align {
+            let (_, cur_align) = this.get_alloc_size_and_align(alloc_id, AllocCheck::MaybeDead)?;
+            if cur_align.bytes() >= req_align {
                 // If the allocation alignment is at least the required alignment we use the
                 // real implementation.
                 return Ok(false);