Skip to content

Commit

Permalink
Fix the problem of sending pointed to thread local statics. Add a reg…
Browse files Browse the repository at this point in the history
…ression test.
  • Loading branch information
Vytautas Astrauskas committed Apr 6, 2020
1 parent eba471d commit 29929d8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
23 changes: 23 additions & 0 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,29 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
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);
Expand Down
10 changes: 10 additions & 0 deletions tests/run-pass/concurrency/simple.stdout
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 12 additions & 4 deletions tests/run-pass/concurrency/thread_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -45,4 +52,5 @@ fn main() {
assert_eq!(C, 24);
}

}
}

1 change: 1 addition & 0 deletions tests/run-pass/concurrency/thread_locals.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WARNING: The thread support is experimental. For example, Miri does not detect data races yet.

0 comments on commit 29929d8

Please sign in to comment.