]> git.lizzy.rs Git - rust.git/commitdiff
Use places instead of ptrs to write packed immtys
authorChristian Poveda <christianpoveda@protonmail.com>
Mon, 14 Oct 2019 14:08:39 +0000 (09:08 -0500)
committerChristian Poveda <christianpoveda@protonmail.com>
Mon, 14 Oct 2019 21:00:40 +0000 (16:00 -0500)
src/helpers.rs
src/shims/time.rs
tests/run-pass/clock.rs

index 3012b1a95541cc706dd0fee0ddcaf587c59a8ee2..9107958e010ce9e25e83930e8c02c39408b23ef7 100644 (file)
@@ -318,27 +318,23 @@ fn libc_ty_layout(&mut self, name: &str) -> InterpResult<'tcx, TyLayout<'tcx>> {
 
     // Writes several `ImmTy`s contiguosly into memory. This is useful when you have to pack
     // different values into a struct.
-    fn write_immediates(
+    fn write_packed_immediates(
         &mut self,
-        ptr: &Pointer<Tag>,
+        place: &MPlaceTy<'tcx, Tag>,
         imms: &[ImmTy<'tcx, Tag>],
     ) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
 
         let tcx = &{ this.tcx.tcx };
 
-        let allocation = this.memory_mut().get_mut(ptr.alloc_id)?;
         let mut offset = Size::from_bytes(0);
 
-        for imm in imms {
-            let size = imm.layout.size;
-            allocation.write_scalar(
-                tcx,
-                ptr.offset(offset, tcx)?,
-                imm.to_scalar()?.into(),
-                size,
+        for &imm in imms {
+            this.write_immediate_to_mplace(
+                *imm,
+                place.offset(offset, None, imm.layout, tcx)?,
             )?;
-            offset += size;
+            offset += imm.layout.size;
         }
 
         Ok(())
index 1b799b1330aa1210ccd58781939b6ce1b5e144f8..0153c1a912df53b8a0f501c386dec3c10dccc898 100644 (file)
@@ -10,7 +10,7 @@
 fn get_time<'tcx>() -> InterpResult<'tcx, Duration> {
     SystemTime::now()
         .duration_since(SystemTime::UNIX_EPOCH)
-        .map_err(|_| err_unsup_format!("Time went backwards").into())
+        .map_err(|_| err_unsup_format!("Times before the Unix epoch are not supported").into())
 }
 
 fn int_to_immty_checked<'tcx>(
@@ -52,7 +52,7 @@ fn clock_gettime(
             return Ok(-1);
         }
 
-        let tp = this.force_ptr(this.read_scalar(tp_op)?.not_undef()?)?;
+        let tp = this.deref_operand(tp_op)?;
 
         let duration = get_time()?;
         let tv_sec = duration.as_secs() as i128;
@@ -63,11 +63,11 @@ fn clock_gettime(
             int_to_immty_checked(tv_nsec, this.libc_ty_layout("c_long")?)?,
         ];
 
-        this.write_immediates(&tp, &imms)?;
+        this.write_packed_immediates(&tp, &imms)?;
 
         Ok(0)
     }
-    // Foreign function used by generic unix
+    // Foreign function used by generic unix (in particular macOS)
     fn gettimeofday(
         &mut self,
         tv_op: OpTy<'tcx, Tag>,
@@ -86,7 +86,7 @@ fn gettimeofday(
             return Ok(-1);
         }
 
-        let tv = this.force_ptr(this.read_scalar(tv_op)?.not_undef()?)?;
+        let tv = this.deref_operand(tv_op)?;
 
         let duration = get_time()?;
         let tv_sec = duration.as_secs() as i128;
@@ -97,7 +97,7 @@ fn gettimeofday(
             int_to_immty_checked(tv_usec, this.libc_ty_layout("suseconds_t")?)?,
         ];
 
-        this.write_immediates(&tv, &imms)?;
+        this.write_packed_immediates(&tv, &imms)?;
 
         Ok(0)
     }
index 987a78fe1f058661a93371f6f3abc661b8377e0e..23f45f91ada14dd5d1c066ac8c782fc1a9731425 100644 (file)
@@ -1,3 +1,4 @@
+// ignore-windows: TODO clock shims are not implemented on Windows
 // compile-flags: -Zmiri-disable-isolation
 
 use std::time::SystemTime;