]> git.lizzy.rs Git - rust.git/commitdiff
Move truncation from the main branch
authorChristian Poveda <christianpoveda@protonmail.com>
Tue, 17 Sep 2019 18:26:12 +0000 (13:26 -0500)
committerChristian Poveda <christianpoveda@protonmail.com>
Tue, 17 Sep 2019 18:26:12 +0000 (13:26 -0500)
src/shims/mod.rs

index f9b89cf553a39e15d929b6c142b6560eb4977519..eea23b6de4e6096887b0759d9bd8b1295018f266 100644 (file)
@@ -27,9 +27,8 @@ fn find_fn(
         }
         // 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 n = this.align_offset(args[0], args[1])?;
             let dest = dest.unwrap();
-            let n = this.truncate(n, dest.layout);
+            let n = this.align_offset(args[0], args[1], dest.layout)?;
             this.write_scalar(Scalar::from_uint(n, dest.layout.size), dest)?;
             this.goto_block(ret)?;
             return Ok(None);
@@ -51,7 +50,8 @@ fn find_fn(
     fn align_offset(
         &mut self,
         ptr_op: OpTy<'tcx, Tag>,
-        align_op: OpTy<'tcx, Tag>
+        align_op: OpTy<'tcx, Tag>,
+        layout: ty::layout::TyLayout<'tcx>,
     ) -> InterpResult<'tcx, u128> {
         let this = self.eval_context_mut();
 
@@ -65,7 +65,7 @@ fn align_offset(
         if let Scalar::Ptr(ptr) = ptr_scalar {
             let cur_align = this.memory().get(ptr.alloc_id)?.align.bytes() as usize;
             if cur_align < req_align {
-                return Ok(u128::max_value());
+                return Ok(this.truncate(u128::max_value(), layout));
             }
         }