]> git.lizzy.rs Git - rust.git/blobdiff - src/shims/mod.rs
Auto merge of #2141 - saethlin:early-diagnostics-ice, r=RalfJung
[rust.git] / src / shims / mod.rs
index 13ea14b4b9d4056835401d6ed320f6f67dccf6b4..f003552434fe9a5c0548165c44dfa476f67c9106 100644 (file)
@@ -29,14 +29,14 @@ fn find_mir_or_eval_fn(
         abi: Abi,
         args: &[OpTy<'tcx, Tag>],
         ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
-        unwind: Option<mir::BasicBlock>,
-    ) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
+        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));
 
         // 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 &[ref ptr, ref align] = check_arg_count(args)?;
+            let [ptr, align] = check_arg_count(args)?;
             if this.align_offset(ptr, align, ret, unwind)? {
                 return Ok(None);
             }
@@ -54,7 +54,7 @@ fn find_mir_or_eval_fn(
         }
 
         // 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
@@ -64,18 +64,17 @@ fn align_offset(
         ptr_op: &OpTy<'tcx, Tag>,
         align_op: &OpTy<'tcx, Tag>,
         ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
-        unwind: Option<mir::BasicBlock>,
+        unwind: StackPopUnwind,
     ) -> InterpResult<'tcx, bool> {
         let this = self.eval_context_mut();
         let (dest, 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() {
@@ -83,13 +82,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);