[C23] Use thread_local semantics (#70107)
[platform/upstream/llvm.git] / clang / test / CodeGen / thread_local.c
1 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -std=c23 -emit-llvm -o - %s | FileCheck %s
2
3 // Ensure that thread_local and _Thread_local emit the same codegen. See
4 // https://github.com/llvm/llvm-project/issues/70068 for details.
5
6 void func(void) {
7   static thread_local int i = 12;
8   static _Thread_local int j = 13;
9
10   extern thread_local int k;
11   extern thread_local int l;
12
13   (void)k;
14   (void)l;
15 }
16
17 // CHECK:      @func.i = internal thread_local global i32 12, align 4
18 // CHECK-NEXT: @func.j = internal thread_local global i32 13, align 4
19 // CHECK-NEXT: @k = external thread_local global i32, align 4
20 // CHECK-NEXT: @l = external thread_local global i32, align 4
21
22 // CHECK:      define dso_local void @func()
23 // CHECK-NEXT: entry:
24 // CHECK-NEXT: %[[K:.+]] = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @k)
25 // CHECK-NEXT: load i32, ptr %[[K]], align 4
26 // CHECK-NEXT: %[[L:.+]] = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @l)
27 // CHECK-NEXT: load i32, ptr %[[L]], align 4