]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/thread-local.rs
Merge commit '54a20a02ecd0e1352a871aa0990bcc8b8b03173e' into clippyup
[rust.git] / src / test / codegen / thread-local.rs
1 // compile-flags: -O
2 // aux-build:thread_local_aux.rs
3 // ignore-windows FIXME(#84933)
4 // ignore-wasm globals are used instead of thread locals
5 // ignore-emscripten globals are used instead of thread locals
6 // ignore-android does not use #[thread_local]
7
8 #![crate_type = "lib"]
9 #![feature(thread_local_const_init)]
10
11 extern crate thread_local_aux as aux;
12
13 use std::cell::Cell;
14
15 thread_local!(static A: Cell<u32> = const { Cell::new(1) });
16
17 // CHECK: [[TLS_AUX:@.+]] = external thread_local local_unnamed_addr global i64
18 // CHECK: [[TLS:@.+]] = internal thread_local unnamed_addr global
19
20 // CHECK-LABEL: @get
21 #[no_mangle]
22 fn get() -> u32 {
23     // CHECK: %0 = load i32, i32* bitcast ({{.*}} [[TLS]] to i32*)
24     // CHECK-NEXT: ret i32 %0
25     A.with(|a| a.get())
26 }
27
28 // CHECK-LABEL: @set
29 #[no_mangle]
30 fn set(v: u32) {
31     // CHECK: store i32 %0, i32* bitcast ({{.*}} [[TLS]] to i32*)
32     // CHECK-NEXT: ret void
33     A.with(|a| a.set(v))
34 }
35
36 // CHECK-LABEL: @get_aux
37 #[no_mangle]
38 fn get_aux() -> u64 {
39     // CHECK: %0 = load i64, i64* [[TLS_AUX]]
40     // CHECK-NEXT: ret i64 %0
41     aux::A.with(|a| a.get())
42 }
43
44 // CHECK-LABEL: @set_aux
45 #[no_mangle]
46 fn set_aux(v: u64) {
47     // CHECK: store i64 %0, i64* [[TLS_AUX]]
48     // CHECK-NEXT: ret void
49     aux::A.with(|a| a.set(v))
50 }