From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/thread-local/name-collision.rs | 15 +++++++++ tests/ui/thread-local/non-static.rs | 30 ++++++++++++++++++ tests/ui/thread-local/non-static.stderr | 38 +++++++++++++++++++++++ tests/ui/thread-local/thread-local-issue-37508.rs | 36 +++++++++++++++++++++ tests/ui/thread-local/tls.rs | 14 +++++++++ 5 files changed, 133 insertions(+) create mode 100644 tests/ui/thread-local/name-collision.rs create mode 100644 tests/ui/thread-local/non-static.rs create mode 100644 tests/ui/thread-local/non-static.stderr create mode 100644 tests/ui/thread-local/thread-local-issue-37508.rs create mode 100644 tests/ui/thread-local/tls.rs (limited to 'tests/ui/thread-local') 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); +} -- cgit v1.2.3