]> git.lizzy.rs Git - rust.git/commitdiff
Fix the problem of sending pointed to thread local statics. Add a regression test.
authorVytautas Astrauskas <astrauv@amazon.com>
Fri, 3 Apr 2020 23:09:42 +0000 (16:09 -0700)
committerVytautas Astrauskas <astrauv@amazon.com>
Mon, 27 Apr 2020 21:23:32 +0000 (14:23 -0700)
src/machine.rs
tests/run-pass/concurrency/simple.stdout [new file with mode: 0644]
tests/run-pass/concurrency/thread_locals.rs
tests/run-pass/concurrency/thread_locals.stdout [new file with mode: 0644]

index e6fea672c608cfba87e2fe9579af4a76d16d1143..7ed5f1e5539f178d1a5a0b0e27176226ecc9e858 100644 (file)
@@ -433,6 +433,29 @@ fn box_alloc(
         Ok(())
     }
 
+    fn access_local(
+        ecx: &InterpCx<'mir, 'tcx, Self>,
+        frame: &Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>,
+        local: mir::Local,
+    ) -> InterpResult<'tcx, Operand<Self::PointerTag>> {
+        match frame.body.local_decls[local].local_info {
+            mir::LocalInfo::StaticRef { def_id, is_thread_local: true } => {
+                let static_alloc_id = ecx.tcx.alloc_map.lock().create_static_alloc(def_id);
+                let alloc_id = ecx.memory.extra.tls.get_or_register_allocation(*ecx.memory.tcx, static_alloc_id);
+                let tag = Self::tag_global_base_pointer(&ecx.memory.extra, alloc_id);
+                let pointer: Pointer = alloc_id.into();
+                let pointer = pointer.with_tag(tag);
+                let scalar: Scalar<_> = pointer.into();
+                let scalar: ScalarMaybeUndef<_> = scalar.into();
+                let immediate: Immediate<_> = scalar.into();
+                Ok(
+                    Operand::Immediate(immediate)
+                )
+            },
+            _ => frame.locals[local].access(),
+        }
+    }
+
     fn canonical_alloc_id(mem: &Memory<'mir, 'tcx, Self>, id: AllocId) -> AllocId {
         let tcx = mem.tcx;
         let alloc = tcx.alloc_map.lock().get(id);
diff --git a/tests/run-pass/concurrency/simple.stdout b/tests/run-pass/concurrency/simple.stdout
new file mode 100644 (file)
index 0000000..0506b7b
--- /dev/null
@@ -0,0 +1,10 @@
+WARNING: The thread support is experimental. For example, Miri does not detect data races yet.
+WARNING: The thread support is experimental. For example, Miri does not detect data races yet.
+WARNING: The thread support is experimental. For example, Miri does not detect data races yet.
+WARNING: The thread support is experimental. For example, Miri does not detect data races yet.
+WARNING: The thread support is experimental. For example, Miri does not detect data races yet.
+WARNING: The thread support is experimental. For example, Miri does not detect data races yet.
+WARNING: The thread support is experimental. For example, Miri does not detect data races yet.
+WARNING: The thread support is experimental. For example, Miri does not detect data races yet.
+WARNING: The thread support is experimental. For example, Miri does not detect data races yet.
+WARNING: The thread support is experimental. For example, Miri does not detect data races yet.
index d0d25ba7f70cb7aa2baee935481e5f4d3bff8c8d..1c268a4ff874a7d046feeb8ccac0e618448451c3 100644 (file)
@@ -12,18 +12,24 @@ unsafe fn get_a_ref() -> *mut u8 {
     &mut A
 }
 
+struct Sender(*mut u8);
+
+unsafe impl Send for Sender {}
+
 fn main() {
 
-    unsafe {
+    let ptr = unsafe {
         let x = get_a_ref();
         *x = 5;
         assert_eq!(A, 5);
         B = 15;
         C = 25;
-    }
+        Sender(&mut A)
+    };
     
-    thread::spawn(|| {
+    thread::spawn(move || {
         unsafe {
+            assert_eq!(*ptr.0, 5);
             assert_eq!(A, 0);
             assert_eq!(B, 0);
             assert_eq!(C, 25);
@@ -32,6 +38,7 @@ fn main() {
             let y = get_a_ref();
             assert_eq!(*y, 0);
             *y = 4;
+            assert_eq!(*ptr.0, 5);
             assert_eq!(A, 4);
             assert_eq!(*get_a_ref(), 4);
             
@@ -45,4 +52,5 @@ fn main() {
         assert_eq!(C, 24);
     }
     
-}
\ No newline at end of file
+}
+
diff --git a/tests/run-pass/concurrency/thread_locals.stdout b/tests/run-pass/concurrency/thread_locals.stdout
new file mode 100644 (file)
index 0000000..9a53b4a
--- /dev/null
@@ -0,0 +1 @@
+WARNING: The thread support is experimental. For example, Miri does not detect data races yet.