about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/tools/miri/src/clock.rs16
-rw-r--r--src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs4
2 files changed, 8 insertions, 12 deletions
diff --git a/src/tools/miri/src/clock.rs b/src/tools/miri/src/clock.rs
index c18e1bc7a9e..da2c54745a0 100644
--- a/src/tools/miri/src/clock.rs
+++ b/src/tools/miri/src/clock.rs
@@ -39,15 +39,11 @@ impl Instant {
                 InstantKind::Virtual { nanoseconds },
                 InstantKind::Virtual { nanoseconds: earlier },
             ) => {
-                // Trade some nanosecond precision to prevent as much overflow as possible.
-                let duration = match u64::try_from(
-                    // Manually convert from nanosecond to millisecond.
-                    // If it exceeded u64::MAX millisecond, we will just use u64::MAX millisecond,
-                    // Duration can't take in more than u64::MAX millisecond.
-                    nanoseconds.saturating_sub(earlier).saturating_div(1_000_000),
-                ) {
-                    Ok(millisecond) => Duration::from_millis(millisecond),
-                    _ => Duration::from_millis(u64::MAX),
+                // If it exceeded u64::MAX nanosecond, we will just keep u64::MAX nanosecond,
+                // Duration can't take in more than u64::MAX.
+                let duration = match u64::try_from(nanoseconds.saturating_sub(earlier)) {
+                    Ok(nanosecond) => Duration::from_nanos(nanosecond),
+                    Err(_err) => Duration::from_nanos(u64::MAX),
                 };
                 Duration::new(duration.as_secs(), duration.subsec_nanos())
             }
@@ -104,7 +100,7 @@ impl Clock {
             ClockKind::Host { .. } => std::thread::sleep(duration),
             ClockKind::Virtual { nanoseconds } => {
                 // Just pretend that we have slept for some time.
-                let nanos: u128 = duration.as_nanos().try_into().unwrap();
+                let nanos: u128 = duration.as_nanos();
                 nanoseconds.update(|x| x + nanos);
             }
         }
diff --git a/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs b/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs
index 59319b93748..5e266c7949f 100644
--- a/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs
+++ b/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs
@@ -280,7 +280,7 @@ fn concurrent_wait_wake() {
     assert!(woken > 0 && woken < rounds);
 }
 
-// Reproduce of https://github.com/rust-lang/miri/issues/3647.
+// Reproduce https://github.com/rust-lang/miri/issues/3647. This should not ICE.
 fn large_timeout() {
     let futex: i32 = 123;
 
@@ -296,7 +296,6 @@ fn large_timeout() {
 }
 
 fn main() {
-    large_timeout();
     wake_nobody();
     wake_dangling();
     wait_wrong_val();
@@ -305,4 +304,5 @@ fn main() {
     wait_wake();
     wait_wake_bitset();
     concurrent_wait_wake();
+    large_timeout();
 }