]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #882 - RalfJung:miri-rustc, r=RalfJung
authorbors <bors@rust-lang.org>
Sun, 4 Aug 2019 08:26:51 +0000 (08:26 +0000)
committerbors <bors@rust-lang.org>
Sun, 4 Aug 2019 08:26:51 +0000 (08:26 +0000)
install xargo from git temporarily

This is so that once https://github.com/japaric/xargo/pull/246 landed, we can see if that helps with https://github.com/rust-lang/rust/pull/63162.

13 files changed:
rust-version
src/eval.rs
src/machine.rs
src/shims/dlsym.rs
src/shims/foreign_items.rs
src/shims/intrinsics.rs
src/shims/tls.rs
src/stacked_borrows.rs
tests/compile-fail/atomic_non_integer_arithmetic.rs [deleted file]
tests/compile-fail/ctlz_nonzero.rs
tests/compile-fail/cttz_nonzero.rs
tests/compile-fail/overflowing-unchecked-rsh.rs
tests/run-pass/intrinsics-math.rs

index f54537d33b937a70cc2910bd663636c96cda9bed..94c6f5e4b8c9790c8135091ff2443a14f884a8bf 100644 (file)
@@ -1 +1 @@
-8e917f48382c6afaf50568263b89d35fba5d98e4
+a45743345659c775b01484574af2818c46a2cb03
index 837757c1ad3b5cfdd0395210c0ea0c20d07057f5..bc9d97b0280f14144b0a1cce9df37d23911d7a69 100644 (file)
@@ -41,10 +41,9 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
     let main_mir = ecx.load_mir(main_instance.def)?;
 
     if !main_mir.return_ty().is_unit() || main_mir.arg_count != 0 {
-        throw_unsup!(Unimplemented(
+        throw_unsup_format!(
             "miri does not support main functions without `fn()` type signatures"
-                .to_owned(),
-        ));
+        );
     }
 
     let start_id = tcx.lang_items().start_fn().unwrap();
@@ -60,10 +59,10 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
     let start_mir = ecx.load_mir(start_instance.def)?;
 
     if start_mir.arg_count != 3 {
-        throw_unsup!(AbiViolation(format!(
+        bug!(
             "'start' lang item should have three arguments, but has {}",
             start_mir.arg_count
-        )));
+        );
     }
 
     // Return value (in static memory so that it does not count as leak).
index 7fa79d822c35b6763758e46127c56475ac0aa4b0..30f3231308a472c8f643708ee50398739ac0373e 100644 (file)
@@ -247,9 +247,7 @@ fn find_foreign_static(
                 let data = vec![0; size.bytes() as usize];
                 Allocation::from_bytes(&data, tcx.data_layout.pointer_align.abi)
             }
-            _ => throw_unsup!(Unimplemented(
-                    format!("can't access foreign static: {}", link_name),
-                )),
+            _ => throw_unsup_format!("can't access foreign static: {}", link_name),
         };
         Ok(Cow::Owned(alloc))
     }
index 005493096248a33e6bb617f7e76211e2780f4aee..b859a8019024564daa8a3d7a17135fb19d0d9e09 100644 (file)
@@ -16,9 +16,7 @@ pub fn from_str(name: &str) -> InterpResult<'static, Option<Dlsym>> {
             "getentropy" => Some(GetEntropy),
             "__pthread_get_minstack" => None,
             _ =>
-                throw_unsup!(Unimplemented(format!(
-                    "Unsupported dlsym: {}", name
-                ))),
+                throw_unsup_format!("Unsupported dlsym: {}", name),
         })
     }
 }
index 12baa79916ab6eaebfce1972b2597af770ae0198..96bc747d3efb057e7aa2dde44e14dee9668b42a1 100644 (file)
@@ -141,7 +141,7 @@ fn emulate_foreign_item(
         // First: functions that diverge.
         match link_name {
             "__rust_start_panic" | "panic_impl" => {
-                throw_unsup!(MachineError("the evaluated program panicked".to_string()));
+                throw_unsup_format!("the evaluated program panicked");
             }
             "exit" | "ExitProcess" => {
                 // it's really u32 for ExitProcess, but we have to put it into the `Exit` error variant anyway
@@ -149,9 +149,7 @@ fn emulate_foreign_item(
                 return Err(InterpError::Exit(code).into());
             }
             _ => if dest.is_none() {
-                throw_unsup!(Unimplemented(
-                    format!("can't call diverging foreign function: {}", link_name),
-                ));
+                throw_unsup_format!("can't call (diverging) foreign function: {}", link_name);
             }
         }
 
@@ -179,16 +177,13 @@ fn emulate_foreign_item(
                 if !align.is_power_of_two() {
                     throw_unsup!(HeapAllocNonPowerOfTwoAlignment(align));
                 }
-                /*
-                FIXME: This check is disabled because rustc violates it.
-                See <https://github.com/rust-lang/rust/issues/62251>.
                 if align < this.pointer_size().bytes() {
-                    throw_unsup!(MachineError(format!(
+                    throw_ub_format!(
                         "posix_memalign: alignment must be at least the size of a pointer, but is {}",
                         align,
-                    )));
+                    );
                 }
-                */
+
                 if size == 0 {
                     this.write_null(ret.into())?;
                 } else {
@@ -309,9 +304,7 @@ fn emulate_foreign_item(
                         this.write_scalar(Scalar::from_uint(len, dest.layout.size), dest)?;
                     }
                     id => {
-                        throw_unsup!(Unimplemented(
-                            format!("miri does not support syscall ID {}", id),
-                        ))
+                        throw_unsup_format!("miri does not support syscall ID {}", id)
                     }
                 }
             }
@@ -359,12 +352,8 @@ fn emulate_foreign_item(
                 )?;
                 let mut args = this.frame().body.args_iter();
 
-                let arg_local = args.next().ok_or_else(||
-                    err_unsup!(AbiViolation(
-                        "Argument to __rust_maybe_catch_panic does not take enough arguments."
-                            .to_owned(),
-                    )),
-                )?;
+                let arg_local = args.next()
+                    .expect("Argument to __rust_maybe_catch_panic does not take enough arguments.");
                 let arg_dest = this.local_place(arg_local)?;
                 this.write_scalar(data, arg_dest)?;
 
@@ -602,6 +591,15 @@ fn emulate_foreign_item(
                 };
                 this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?;
             }
+            // underscore case for windows
+            "_ldexp" | "ldexp" => {
+                // FIXME: Using host floats.
+                let x = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
+                let exp = this.read_scalar(args[1])?.to_i32()?;
+                // FIXME: We should use cmath if there are any imprecisions.
+                let n = x * 2.0f64.powi(exp);
+                this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?;
+            }
 
             // Some things needed for `sys::thread` initialization to go through.
             "signal" | "sigaction" | "sigaltstack" => {
@@ -632,9 +630,7 @@ fn emulate_foreign_item(
                 if let Some(result) = result {
                     this.write_scalar(result, dest)?;
                 } else {
-                    throw_unsup!(Unimplemented(
-                        format!("Unimplemented sysconf name: {}", name),
-                    ));
+                    throw_unsup_format!("Unimplemented sysconf name: {}", name)
                 }
             }
 
@@ -661,9 +657,9 @@ fn emulate_foreign_item(
                 // This is `libc::pthread_key_t`.
                 let key_type = args[0].layout.ty
                     .builtin_deref(true)
-                    .ok_or_else(|| err_unsup!(
-                        AbiViolation("wrong signature used for `pthread_key_create`: first argument must be a raw pointer.".to_owned())
-                    ))?
+                    .ok_or_else(|| err_ub!(Ub(format!(
+                        "wrong signature used for `pthread_key_create`: first argument must be a raw pointer."
+                    ))))?
                     .ty;
                 let key_layout = this.layout_of(key_type)?;
 
@@ -729,7 +725,7 @@ fn emulate_foreign_item(
 
             // We don't support threading. (Also for Windows.)
             "pthread_create" | "CreateThread" => {
-                throw_unsup!(Unimplemented(format!("Miri does not support threading")));
+                throw_unsup_format!("Miri does not support threading");
             }
 
             // Stub out calls for condvar, mutex and rwlock, to just return `0`.
@@ -948,9 +944,7 @@ fn emulate_foreign_item(
 
             // We can't execute anything else.
             _ => {
-                throw_unsup!(Unimplemented(
-                    format!("can't call foreign function: {}", link_name),
-                ));
+                throw_unsup_format!("can't call foreign function: {}", link_name)
             }
         }
 
@@ -974,4 +968,4 @@ fn eval_path_scalar(&mut self, path: &[&str]) -> InterpResult<'tcx, Option<Scala
         }
         return Ok(None);
     }
-}
\ No newline at end of file
+}
index 7a213a8059967a46d3a9aae137df6ac0efba70b8..5c3ff139c0262f7ee62b3fc75e95717c1569e498 100644 (file)
@@ -133,7 +133,7 @@ fn call_intrinsic(
             "atomic_xsub_relaxed" => {
                 let ptr = this.deref_operand(args[0])?;
                 if !ptr.layout.ty.is_integral() {
-                    throw_unsup!(Unimplemented(format!("Atomic arithmetic operations only work on integer types")));
+                    bug!("Atomic arithmetic operations only work on integer types");
                 }
                 let rhs = this.read_immediate(args[1])?;
                 let old = this.read_immediate(ptr.into())?;
@@ -279,9 +279,9 @@ fn call_intrinsic(
                     // Check if `b` is -1, which is the "min_value / -1" case.
                     let minus1 = Scalar::from_int(-1, dest.layout.size);
                     return Err(if b.to_scalar().unwrap() == minus1 {
-                        err_unsup!(Intrinsic(format!("exact_div: result of dividing MIN by -1 cannot be represented")))
+                        err_ub!(Ub(format!("exact_div: result of dividing MIN by -1 cannot be represented")))
                     } else {
-                        err_unsup!(Intrinsic(format!("exact_div: {:?} cannot be divided by {:?} without remainder", *a, *b)))
+                        err_ub!(Ub(format!("exact_div: {:?} cannot be divided by {:?} without remainder", *a, *b)))
                     }.into());
                 }
                 this.binop_ignore_overflow(mir::BinOp::Div, a, b, dest)?;
@@ -350,7 +350,7 @@ fn call_intrinsic(
                 let ty = substs.type_at(0);
                 let layout = this.layout_of(ty)?;
                 if layout.abi.is_uninhabited() {
-                    throw_unsup!(Intrinsic(format!("Trying to instantiate uninhabited type {}", ty)))
+                    throw_ub_format!("Trying to instantiate uninhabited type {}", ty)
                 }
             }
 
@@ -444,7 +444,7 @@ fn call_intrinsic(
                 let r = this.read_immediate(args[1])?;
                 let rval = r.to_scalar()?.to_bits(args[1].layout.size)?;
                 if rval == 0 {
-                    throw_unsup!(Intrinsic(format!("Division by 0 in unchecked_div")));
+                    throw_ub_format!("Division by 0 in unchecked_div");
                 }
                 this.binop_ignore_overflow(
                     mir::BinOp::Div,
@@ -459,7 +459,7 @@ fn call_intrinsic(
                 let r = this.read_immediate(args[1])?;
                 let rval = r.to_scalar()?.to_bits(args[1].layout.size)?;
                 if rval == 0 {
-                    throw_unsup!(Intrinsic(format!("Division by 0 in unchecked_rem")));
+                    throw_ub_format!("Division by 0 in unchecked_rem");
                 }
                 this.binop_ignore_overflow(
                     mir::BinOp::Rem,
@@ -480,7 +480,7 @@ fn call_intrinsic(
                 };
                 let (res, overflowed) = this.binary_op(op, l, r)?;
                 if overflowed {
-                    throw_unsup!(Intrinsic(format!("Overflowing arithmetic in {}", intrinsic_name.get())));
+                    throw_ub_format!("Overflowing arithmetic in {}", intrinsic_name.get());
                 }
                 this.write_scalar(res, dest)?;
             }
@@ -504,7 +504,7 @@ fn call_intrinsic(
                 }
             }
 
-            name => throw_unsup!(Unimplemented(format!("unimplemented intrinsic: {}", name))),
+            name => throw_unsup_format!("unimplemented intrinsic: {}", name),
         }
 
         Ok(())
index 145d2b3e78915e3fee8eccc2a5bfdfc0974cc8e1..05b8dc15da66be66d9131699e49cdd8ec918aaa1 100644 (file)
@@ -158,7 +158,7 @@ fn run_tls_dtors(&mut self) -> InterpResult<'tcx> {
                 StackPopCleanup::None { cleanup: true },
             )?;
             let arg_local = this.frame().body.args_iter().next().ok_or_else(
-                || err_unsup!(AbiViolation("TLS dtor does not take enough arguments.".to_owned())),
+                || err_ub!(Ub(format!("TLS dtor does not take enough arguments."))),
             )?;
             let dest = this.local_place(arg_local)?;
             this.write_scalar(ptr, dest)?;
index 5ef934b9922b3be857e8e9647c7b839a3115b2ae..0fbc3e1ac281df374c300970d6eb34d070d97aa0 100644 (file)
@@ -273,14 +273,14 @@ fn check_protector(item: &Item, tag: Option<Tag>, global: &GlobalState) -> Inter
         if let Some(call) = item.protector {
             if global.is_active(call) {
                 if let Some(tag) = tag {
-                    throw_unsup!(MachineError(format!(
+                    throw_ub_format!(
                         "not granting access to tag {:?} because incompatible item is protected: {:?}",
                         tag, item
-                    )));
+                    );
                 } else {
-                    throw_unsup!(MachineError(format!(
+                    throw_ub_format!(
                         "deallocating while item is protected: {:?}", item
-                    )));
+                    );
                 }
             }
         }
@@ -299,7 +299,7 @@ fn access(
 
         // Step 1: Find granting item.
         let granting_idx = self.find_granting(access, tag)
-            .ok_or_else(|| err_unsup!(MachineError(format!(
+            .ok_or_else(|| err_ub!(Ub(format!(
                 "no item granting {} to tag {:?} found in borrow stack",
                 access, tag,
             ))))?;
@@ -346,7 +346,7 @@ fn dealloc(
     ) -> InterpResult<'tcx> {
         // Step 1: Find granting item.
         self.find_granting(AccessKind::Write, tag)
-            .ok_or_else(|| err_unsup!(MachineError(format!(
+            .ok_or_else(|| err_ub!(Ub(format!(
                 "no item granting write access for deallocation to tag {:?} found in borrow stack",
                 tag,
             ))))?;
@@ -378,7 +378,7 @@ fn grant(
         // Now we figure out which item grants our parent (`derived_from`) this kind of access.
         // We use that to determine where to put the new item.
         let granting_idx = self.find_granting(access, derived_from)
-            .ok_or_else(|| err_unsup!(MachineError(format!(
+            .ok_or_else(|| err_ub!(Ub(format!(
                 "trying to reborrow for {:?}, but parent tag {:?} does not have an appropriate item in the borrow stack", new.perm, derived_from,
             ))))?;
 
diff --git a/tests/compile-fail/atomic_non_integer_arithmetic.rs b/tests/compile-fail/atomic_non_integer_arithmetic.rs
deleted file mode 100644 (file)
index 8c2ed98..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#![feature(core_intrinsics)]
-
-pub fn main() {
-    let mut z: f64 = 1.0;
-    unsafe {
-        ::std::intrinsics::atomic_xadd(&mut z, 2.0);
-        //~^ ERROR: Atomic arithmetic operations only work on integer types
-    }
-}
index 61f41363589cae96c1dbf138fadbfa12052ad0ce..e82ed89da18a742d446f277e258623a9fb01537a 100644 (file)
@@ -10,6 +10,6 @@ pub fn main() {
     unsafe {
         use crate::rusti::*;
 
-        ctlz_nonzero(0u8); //~ ERROR ctlz_nonzero called on 0
+        ctlz_nonzero(0u8); //~ ERROR `ctlz_nonzero` called on 0
     }
 }
index 69d2874ce92698e3330073a3304f81065e6aa221..205b5520811481f069c86c10cfd77798c262a92f 100644 (file)
@@ -10,6 +10,6 @@ pub fn main() {
     unsafe {
         use crate::rusti::*;
 
-        cttz_nonzero(0u8); //~ ERROR cttz_nonzero called on 0
+        cttz_nonzero(0u8); //~ ERROR `cttz_nonzero` called on 0
     }
 }
index 0d67aef43088335be31e70d974af9a635e27eb20..f59773f7e366ce5a5266ff245de30ef807adfd75 100644 (file)
@@ -2,7 +2,7 @@
 
 use std::intrinsics::*;
 
-//error-pattern: Overflowing shift by 64 in unchecked_shr
+//error-pattern: Overflowing shift by 64 in `unchecked_shr`
 
 fn main() {
     unsafe {
index 20c0f674948869308c32547b1ea6d1a382e6bbd6..9a7a70bd00925e0ac58c7d6575710acba195d750 100644 (file)
@@ -85,4 +85,8 @@ pub fn main() {
     assert_approx_eq!(1.0f32.tan(), 1.557408f32);
     assert_approx_eq!(1.0f64.tan(), 1.557408f64);
 
+    extern {
+        fn ldexp(x: f64, n: i32) -> f64;
+    }
+    unsafe { assert_approx_eq!(ldexp(0.65f64, 3i32), 5.2f64); }
 }