diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/thread-local | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/thread-local')
-rw-r--r-- | tests/ui/thread-local/name-collision.rs | 15 | ||||
-rw-r--r-- | tests/ui/thread-local/non-static.rs | 30 | ||||
-rw-r--r-- | tests/ui/thread-local/non-static.stderr | 38 | ||||
-rw-r--r-- | tests/ui/thread-local/thread-local-issue-37508.rs | 36 | ||||
-rw-r--r-- | tests/ui/thread-local/tls.rs | 14 |
5 files changed, 133 insertions, 0 deletions
diff --git a/tests/ui/thread-local/name-collision.rs b/tests/ui/thread-local/name-collision.rs new file mode 100644 index 000000000..dcff9183a --- /dev/null +++ b/tests/ui/thread-local/name-collision.rs @@ -0,0 +1,15 @@ +// check-pass + +#[allow(non_camel_case_types)] +struct u8; + +std::thread_local! { + pub static A: i32 = f(); + pub static B: i32 = const { 0 }; +} + +fn f() -> i32 { + 0 +} + +fn main() {} diff --git a/tests/ui/thread-local/non-static.rs b/tests/ui/thread-local/non-static.rs new file mode 100644 index 000000000..f1c427387 --- /dev/null +++ b/tests/ui/thread-local/non-static.rs @@ -0,0 +1,30 @@ +// Check that #[thread_local] attribute is rejected on non-static items. +#![feature(thread_local)] + +#[thread_local] +//~^ ERROR attribute should be applied to a static +const A: u32 = 0; + +#[thread_local] +//~^ ERROR attribute should be applied to a static +fn main() { + #[thread_local] || {}; + //~^ ERROR attribute should be applied to a static +} + +struct S { + #[thread_local] + //~^ ERROR attribute should be applied to a static + a: String, + b: String, +} + +#[thread_local] +// Static. OK. +static B: u32 = 0; + +extern "C" { + #[thread_local] + // Foreign static. OK. + static C: u32; +} diff --git a/tests/ui/thread-local/non-static.stderr b/tests/ui/thread-local/non-static.stderr new file mode 100644 index 000000000..09a1618d6 --- /dev/null +++ b/tests/ui/thread-local/non-static.stderr @@ -0,0 +1,38 @@ +error: attribute should be applied to a static + --> $DIR/non-static.rs:4:1 + | +LL | #[thread_local] + | ^^^^^^^^^^^^^^^ +LL | +LL | const A: u32 = 0; + | ----------------- not a static + +error: attribute should be applied to a static + --> $DIR/non-static.rs:8:1 + | +LL | #[thread_local] + | ^^^^^^^^^^^^^^^ +LL | +LL | / fn main() { +LL | | #[thread_local] || {}; +LL | | +LL | | } + | |_- not a static + +error: attribute should be applied to a static + --> $DIR/non-static.rs:11:5 + | +LL | #[thread_local] || {}; + | ^^^^^^^^^^^^^^^ ----- not a static + +error: attribute should be applied to a static + --> $DIR/non-static.rs:16:5 + | +LL | #[thread_local] + | ^^^^^^^^^^^^^^^ +LL | +LL | a: String, + | --------- not a static + +error: aborting due to 4 previous errors + diff --git a/tests/ui/thread-local/thread-local-issue-37508.rs b/tests/ui/thread-local/thread-local-issue-37508.rs new file mode 100644 index 000000000..219108c77 --- /dev/null +++ b/tests/ui/thread-local/thread-local-issue-37508.rs @@ -0,0 +1,36 @@ +// only-x86_64 +// compile-flags: -Ccode-model=large --crate-type lib +// build-pass +// +// Regression test for issue #37508 + +#![no_main] +#![no_std] +#![feature(thread_local, lang_items)] + +#[lang = "eh_personality"] +extern "C" fn eh_personality() {} + +use core::panic::PanicInfo; + +#[panic_handler] +fn panic(_panic: &PanicInfo<'_>) -> ! { + loop {} +} + +pub struct BB; + +#[thread_local] +static mut KEY: Key = Key { inner: BB, dtor_running: false }; + +pub unsafe fn set() -> Option<&'static BB> { + if KEY.dtor_running { + return None; + } + Some(&KEY.inner) +} + +pub struct Key { + inner: BB, + dtor_running: bool, +} diff --git a/tests/ui/thread-local/tls.rs b/tests/ui/thread-local/tls.rs new file mode 100644 index 000000000..fbd341388 --- /dev/null +++ b/tests/ui/thread-local/tls.rs @@ -0,0 +1,14 @@ +// run-pass +// ignore-emscripten no threads support +// compile-flags: -O + +#![feature(thread_local)] + +#[thread_local] +static S: u32 = 222; + +fn main() { + let local = &S as *const u32 as usize; + let foreign = std::thread::spawn(|| &S as *const u32 as usize).join().unwrap(); + assert_ne!(local, foreign); +} |