1 // RUN: %clang_cc1 %s -std=c++1y -triple=i686-pc-win32 -emit-llvm -o - | FileCheck %s
2 // RUN: %clang_cc1 %s  -std=c++1y -triple=i686-pc-win32 -ftls-model=local-dynamic -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-LD
3 
4 struct A {
5   A();
6   ~A();
7 };
8 
9 // CHECK-DAG: $"??$a@X@@3UA@@A" = comdat any
10 // CHECK-DAG: @"??$a@X@@3UA@@A" = linkonce_odr dso_local thread_local global %struct.A zeroinitializer, comdat, align 1
11 // CHECK-DAG: @"??__E?$a@X@@YAXXZ$initializer$" = internal constant void ()* @"??__E?$a@X@@YAXXZ", section ".CRT$XDU", comdat($"??$a@X@@3UA@@A")
12 // CHECK-LD-DAG: $"??$a@X@@3UA@@A" = comdat any
13 // CHECK-LD-DAG: @"??$a@X@@3UA@@A" = linkonce_odr dso_local thread_local(localdynamic) global %struct.A zeroinitializer, comdat, align 1
14 // CHECK-LD-DAG: @"??__E?$a@X@@YAXXZ$initializer$" = internal constant void ()* @"??__E?$a@X@@YAXXZ", section ".CRT$XDU", comdat($"??$a@X@@3UA@@A")
15 template <typename T>
16 thread_local A a = A();
17 
18 // CHECK-DAG: @"?b@@3UA@@A" = dso_local thread_local global %struct.A zeroinitializer, align 1
19 // CHECK-DAG: @"__tls_init$initializer$" = internal constant void ()* @__tls_init, section ".CRT$XDU"
20 // CHECK-LD-DAG: @"?b@@3UA@@A" = dso_local thread_local(localdynamic) global %struct.A zeroinitializer, align 1
21 // CHECK-LD-DAG: @"__tls_init$initializer$" = internal constant void ()* @__tls_init, section ".CRT$XDU"
22 thread_local A b;
23 
24 // CHECK-LABEL: define internal void @__tls_init()
25 // CHECK: call void @"??__Eb@@YAXXZ"
26 // CHECK-LD-LABEL: define internal void @__tls_init()
27 // CHECK-LD: call void @"??__Eb@@YAXXZ"
28 
29 thread_local A &c = b;
30 thread_local A &d = c;
31 
f()32 A f() {
33   (void)a<void>;
34   (void)b;
35   return c;
36 }
37 
38 // CHECK: !llvm.linker.options = !{![[dyn_tls_init:[0-9]+]]}
39 // CHECK: ![[dyn_tls_init]] = !{!"/include:___dyn_tls_init@12"}
40 // CHECK-LD: !llvm.linker.options = !{![[dyn_tls_init:[0-9]+]]}
41 // CHECK-LD: ![[dyn_tls_init]] = !{!"/include:___dyn_tls_init@12"}
42