2021-05-03 13:39:10 -05:00
|
|
|
// compile-flags: -O
|
|
|
|
// aux-build:thread_local_aux.rs
|
|
|
|
// ignore-windows FIXME(#84933)
|
|
|
|
// ignore-wasm globals are used instead of thread locals
|
|
|
|
// ignore-emscripten globals are used instead of thread locals
|
|
|
|
// ignore-android does not use #[thread_local]
|
2023-01-10 03:44:05 -06:00
|
|
|
// ignore-nto does not use #[thread_local]
|
2021-05-03 13:39:10 -05:00
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
|
|
|
|
extern crate thread_local_aux as aux;
|
|
|
|
|
|
|
|
use std::cell::Cell;
|
|
|
|
|
|
|
|
thread_local!(static A: Cell<u32> = const { Cell::new(1) });
|
|
|
|
|
|
|
|
// CHECK: [[TLS_AUX:@.+]] = external thread_local local_unnamed_addr global i64
|
|
|
|
// CHECK: [[TLS:@.+]] = internal thread_local unnamed_addr global
|
|
|
|
|
|
|
|
// CHECK-LABEL: @get
|
|
|
|
#[no_mangle]
|
|
|
|
fn get() -> u32 {
|
2023-04-17 09:53:18 -05:00
|
|
|
// CHECK: [[RET_0:%.+]] = load i32, {{.*}}[[TLS]]{{.*}}
|
|
|
|
// CHECK-NEXT: ret i32 [[RET_0]]
|
2021-05-03 13:39:10 -05:00
|
|
|
A.with(|a| a.get())
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @set
|
|
|
|
#[no_mangle]
|
|
|
|
fn set(v: u32) {
|
2022-02-21 04:21:23 -06:00
|
|
|
// CHECK: store i32 %0, {{.*}}[[TLS]]{{.*}}
|
2021-05-03 13:39:10 -05:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
A.with(|a| a.set(v))
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @get_aux
|
|
|
|
#[no_mangle]
|
|
|
|
fn get_aux() -> u64 {
|
2023-04-17 09:53:18 -05:00
|
|
|
// CHECK: [[RET_1:%.+]] = load i64, {{.*}}[[TLS_AUX]]
|
|
|
|
// CHECK-NEXT: ret i64 [[RET_1]]
|
2021-05-03 13:39:10 -05:00
|
|
|
aux::A.with(|a| a.get())
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @set_aux
|
|
|
|
#[no_mangle]
|
|
|
|
fn set_aux(v: u64) {
|
2022-02-21 04:21:23 -06:00
|
|
|
// CHECK: store i64 %0, {{.*}}[[TLS_AUX]]
|
2021-05-03 13:39:10 -05:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
aux::A.with(|a| a.set(v))
|
|
|
|
}
|