[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / ms-thread_local.cpp
bloba6c62967f23dec7ddf13637c1527f5cc195c2037
1 // RUN: %clang_cc1 %s -std=c++1y -triple=i686-pc-win32 -fms-compatibility-version=19.25 -emit-llvm -o - | FileCheck %s
2 // RUN: %clang_cc1 %s -std=c++1y -triple=i686-pc-win32 -fms-compatibility-version=19.20 -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-LEGACY
3 // RUN: %clang_cc1 %s -std=c++1y -triple=i686-pc-win32 -fms-compatibility-version=19.25 -ftls-model=local-dynamic -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-LD
5 struct A {
6 A();
7 ~A();
8 };
10 // CHECK-DAG: $"??$a@X@@3UA@@A" = comdat any
11 // CHECK-DAG: @"??$a@X@@3UA@@A" = linkonce_odr dso_local thread_local global %struct.A zeroinitializer, comdat, align 1
12 // CHECK-DAG: @"??__E?$a@X@@YAXXZ$initializer$" = internal constant ptr @"??__E?$a@X@@YAXXZ", section ".CRT$XDU", comdat($"??$a@X@@3UA@@A")
13 // CHECK-LD-DAG: $"??$a@X@@3UA@@A" = comdat any
14 // CHECK-LD-DAG: @"??$a@X@@3UA@@A" = linkonce_odr dso_local thread_local(localdynamic) global %struct.A zeroinitializer, comdat, align 1
15 // CHECK-LD-DAG: @"??__E?$a@X@@YAXXZ$initializer$" = internal constant ptr @"??__E?$a@X@@YAXXZ", section ".CRT$XDU", comdat($"??$a@X@@3UA@@A")
16 template <typename T>
17 thread_local A a = A();
19 // CHECK-DAG: @"?b@@3UA@@A" = dso_local thread_local global %struct.A zeroinitializer, align 1
20 // CHECK-DAG: @"__tls_init$initializer$" = internal constant ptr @__tls_init, section ".CRT$XDU"
21 // CHECK-DAG: @__tls_guard = external dso_local thread_local global i8
22 // CHECK-LD-DAG: @"?b@@3UA@@A" = dso_local thread_local(localdynamic) global %struct.A zeroinitializer, align 1
23 // CHECK-LD-DAG: @"__tls_init$initializer$" = internal constant ptr @__tls_init, section ".CRT$XDU"
24 // CHECK-LD-DAG: @__tls_guard = external dso_local thread_local global i8
25 // CHECK-LEGACY-NOT: @__tls_guard = external dso_local thread_local global i8
26 thread_local A b;
28 // CHECK-LABEL: declare dso_local void @__dyn_tls_on_demand_init()
29 // CHECK-LD-LABEL: declare dso_local void @__dyn_tls_on_demand_init()
30 // CHECK-LEGACY-NOT: declare dso_local void @__dyn_tls_on_demand_init()
32 // CHECK-LABEL: define dso_local void @"?f@@YA?AUA@@XZ"(ptr noalias sret(%struct.A) align 1 %agg.result)
33 // CHECK: call void @__dyn_tls_on_demand_init()
34 // CHECK-LD-LABEL: define dso_local void @"?f@@YA?AUA@@XZ"(ptr noalias sret(%struct.A) align 1 %agg.result)
35 // CHECK-LD: call void @__dyn_tls_on_demand_init()
36 // CHECK-LEGACY-NOT: call void @__dyn_tls_on_demand_init()
38 thread_local A &c = b;
39 thread_local A &d = c;
41 A f() {
42 (void)a<void>;
43 (void)b;
44 return c;
47 // CHECK-LABEL: define dso_local noundef i32 @"?g@@YAHXZ"()
48 // CHECK-NOT: call void @__dyn_tls_on_demand_init()
49 // CHECK-LD-LABEL: define dso_local noundef i32 @"?g@@YAHXZ"()
50 // CHECK-LD-NOT: call void @__dyn_tls_on_demand_init()
52 thread_local int e = 2;
54 int g() {
55 return e;
58 // CHECK-LABEL: define internal void @__tls_init()
59 // CHECK: call void @"??__Eb@@YAXXZ"
60 // CHECK-LD-LABEL: define internal void @__tls_init()
61 // CHECK-LD: call void @"??__Eb@@YAXXZ"
63 // CHECK: !llvm.linker.options = !{![[dyn_tls_init:[0-9]+]]}
64 // CHECK: ![[dyn_tls_init]] = !{!"/include:___dyn_tls_init@12"}
65 // CHECK-LD: !llvm.linker.options = !{![[dyn_tls_init:[0-9]+]]}
66 // CHECK-LD: ![[dyn_tls_init]] = !{!"/include:___dyn_tls_init@12"}