Skip to content

Commit 602e757

Browse files
committed
assert alignment of thread_local statics
1 parent 1e8ff95 commit 602e757

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/tools/miri/tests/pass/static_align.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ thread_local! {
2828
static HASDROP_CONST_LOCAL: HasDrop = const { HasDrop };
2929
}
3030

31+
fn thread_local_addr<T>(key: &'static std::thread::LocalKey<T>) -> usize {
32+
key.with(|local| core::ptr::from_ref::<T>(local).addr())
33+
}
34+
3135
fn main() {
3236
assert!(core::ptr::from_ref(&FOO).addr().is_multiple_of(256));
3337
assert!(core::ptr::from_ref(&BAR).addr().is_multiple_of(512));
34-
LOCAL.with(|local| core::ptr::from_ref(&local).addr().is_multiple_of(512));
35-
CONST_LOCAL.with(|local| core::ptr::from_ref(&local).addr().is_multiple_of(512));
36-
HASDROP_LOCAL.with(|local| core::ptr::from_ref(&local).addr().is_multiple_of(512));
37-
HASDROP_CONST_LOCAL.with(|local| core::ptr::from_ref(&local).addr().is_multiple_of(512));
38+
39+
assert!(thread_local_addr(&LOCAL).is_multiple_of(512));
40+
assert!(thread_local_addr(&CONST_LOCAL).is_multiple_of(512));
41+
assert!(thread_local_addr(&HASDROP_LOCAL).is_multiple_of(512));
42+
assert!(thread_local_addr(&HASDROP_CONST_LOCAL).is_multiple_of(512));
3843
}

tests/ui/static/static-align.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@ thread_local! {
3737
static HASDROP_CONST_LOCAL: HasDrop = const { HasDrop };
3838
}
3939

40+
fn thread_local_addr<T>(key: &'static std::thread::LocalKey<T>) -> usize {
41+
key.with(|local| core::ptr::from_ref::<T>(local).addr())
42+
}
43+
4044
fn main() {
4145
assert!(core::ptr::from_ref(&A).addr().is_multiple_of(64));
4246
assert!(core::ptr::from_ref(&B).addr().is_multiple_of(4096));
4347

4448
assert!(core::ptr::from_ref(&EXPORTED).addr().is_multiple_of(128));
4549
unsafe { assert!(core::ptr::from_ref(&C).addr().is_multiple_of(128)) };
4650

47-
LOCAL.with(|local| core::ptr::from_ref(&local).addr().is_multiple_of(4096));
48-
CONST_LOCAL.with(|local| core::ptr::from_ref(&local).addr().is_multiple_of(4096));
49-
HASDROP_LOCAL.with(|local| core::ptr::from_ref(&local).addr().is_multiple_of(4096));
50-
HASDROP_CONST_LOCAL.with(|local| core::ptr::from_ref(&local).addr().is_multiple_of(4096));
51+
assert!(thread_local_addr(&LOCAL).is_multiple_of(4096));
52+
assert!(thread_local_addr(&CONST_LOCAL).is_multiple_of(4096));
53+
assert!(thread_local_addr(&HASDROP_LOCAL).is_multiple_of(4096));
54+
assert!(thread_local_addr(&HASDROP_CONST_LOCAL).is_multiple_of(4096));
5155
}

0 commit comments

Comments
 (0)