|
| 1 | +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir |
| 2 | +// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s |
| 3 | +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll |
| 4 | +// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s |
| 5 | +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.og.ll |
| 6 | +// RUN: FileCheck --check-prefix=OGCG --input-file=%t.og.ll %s |
| 7 | + |
| 8 | +// Test basic thread_local variable with constant initialization |
| 9 | +thread_local int tls_const = 42; |
| 10 | +// CIR: cir.global{{.*}}tls_dyn{{.*}}@tls_const = #cir.int<42> : !s32i |
| 11 | +// LLVM: @tls_const = thread_local global i32 42 |
| 12 | +// OGCG: @tls_const = thread_local global i32 42 |
| 13 | + |
| 14 | +// Test __thread (GNU-style) thread_local |
| 15 | +__thread int tls_gnu_style = 10; |
| 16 | +// CIR: cir.global{{.*}}tls_dyn{{.*}}@tls_gnu_style = #cir.int<10> : !s32i |
| 17 | +// LLVM: @tls_gnu_style = thread_local global i32 10 |
| 18 | +// OGCG: @tls_gnu_style = thread_local global i32 10 |
| 19 | + |
| 20 | +// Test thread_local function-local static (constant init) |
| 21 | +int get_tls_static() { |
| 22 | + thread_local int tls_func_static = 100; |
| 23 | + return ++tls_func_static; |
| 24 | +} |
| 25 | +// CIR-LABEL: cir.func{{.*}}@_Z14get_tls_staticv |
| 26 | +// CIR: cir.get_global{{.*}}@_ZZ14get_tls_staticvE15tls_func_static |
| 27 | +// LLVM-LABEL: @_Z14get_tls_staticv |
| 28 | +// LLVM: load{{.*}}@_ZZ14get_tls_staticvE15tls_func_static |
| 29 | +// OGCG-LABEL: @_Z14get_tls_staticv |
| 30 | + |
| 31 | +// Test reading from thread_local variable |
| 32 | +int read_tls() { |
| 33 | + return tls_const; |
| 34 | +} |
| 35 | +// CIR-LABEL: cir.func{{.*}}@_Z8read_tlsv |
| 36 | +// CIR: cir.get_global thread_local @tls_const |
| 37 | +// LLVM-LABEL: @_Z8read_tlsv |
| 38 | +// LLVM: @llvm.threadlocal.address.p0(ptr @tls_const) |
| 39 | +// OGCG-LABEL: @_Z8read_tlsv |
| 40 | +// OGCG: @llvm.threadlocal.address.p0(ptr{{.*}}@tls_const) |
| 41 | + |
| 42 | +// Test writing to thread_local variable |
| 43 | +void write_tls(int val) { |
| 44 | + tls_const = val; |
| 45 | +} |
| 46 | +// CIR-LABEL: cir.func{{.*}}@_Z9write_tlsi |
| 47 | +// CIR: cir.get_global thread_local @tls_const |
| 48 | +// CIR: cir.store |
| 49 | +// LLVM-LABEL: @_Z9write_tlsi |
| 50 | +// LLVM: @llvm.threadlocal.address.p0(ptr @tls_const) |
| 51 | +// OGCG-LABEL: @_Z9write_tlsi |
| 52 | +// OGCG: @llvm.threadlocal.address.p0(ptr{{.*}}@tls_const) |
| 53 | + |
| 54 | +// Test extern thread_local |
| 55 | +extern thread_local int tls_extern; |
| 56 | +int use_extern_tls() { |
| 57 | + return tls_extern; |
| 58 | +} |
| 59 | +// CIR-LABEL: cir.func{{.*}}@_Z14use_extern_tlsv |
| 60 | +// CIR: cir.get_global thread_local @tls_extern |
| 61 | +// LLVM-LABEL: @_Z14use_extern_tlsv |
| 62 | +// OGCG-LABEL: @_Z14use_extern_tlsv |
0 commit comments