2022-04-07 18:03:55 +08:00
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers %s -std=c++1y -triple=i686-pc-win32 -fms-compatibility-version=19.25 -emit-llvm -o - | FileCheck %s
|
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers %s -std=c++1y -triple=i686-pc-win32 -fms-compatibility-version=19.20 -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-LEGACY
|
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers %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
|
2014-10-05 13:05:40 +08:00
|
|
|
|
|
|
|
struct A {
|
|
|
|
A();
|
|
|
|
~A();
|
|
|
|
};
|
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-DAG: $"??$a@X@@3UA@@A" = comdat any
|
|
|
|
// CHECK-DAG: @"??$a@X@@3UA@@A" = linkonce_odr dso_local thread_local global %struct.A zeroinitializer, comdat, align 1
|
|
|
|
// CHECK-DAG: @"??__E?$a@X@@YAXXZ$initializer$" = internal constant void ()* @"??__E?$a@X@@YAXXZ", section ".CRT$XDU", comdat($"??$a@X@@3UA@@A")
|
2020-06-16 14:30:36 +08:00
|
|
|
// CHECK-LD-DAG: $"??$a@X@@3UA@@A" = comdat any
|
|
|
|
// CHECK-LD-DAG: @"??$a@X@@3UA@@A" = linkonce_odr dso_local thread_local(localdynamic) global %struct.A zeroinitializer, comdat, align 1
|
|
|
|
// CHECK-LD-DAG: @"??__E?$a@X@@YAXXZ$initializer$" = internal constant void ()* @"??__E?$a@X@@YAXXZ", section ".CRT$XDU", comdat($"??$a@X@@3UA@@A")
|
2014-10-05 13:05:40 +08:00
|
|
|
template <typename T>
|
|
|
|
thread_local A a = A();
|
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-DAG: @"?b@@3UA@@A" = dso_local thread_local global %struct.A zeroinitializer, align 1
|
2014-10-05 13:05:40 +08:00
|
|
|
// CHECK-DAG: @"__tls_init$initializer$" = internal constant void ()* @__tls_init, section ".CRT$XDU"
|
[MS] Implement on-demand TLS initialization for Microsoft CXX ABI
TLS initializers, for example constructors of thread-local variables, don't necessarily get called. If a thread was created before a module is loaded, the module's TLS initializers are not executed for this particular thread.
This is why Microsoft added support for dynamic TLS initialization. Before every use of thread-local variables, a check is added that runs the module's TLS initializers on-demand.
To do this, the method `__dyn_tls_on_demand_init` gets called. Internally, it simply calls `__dyn_tls_init`.
No additional TLS initializer that sets the guard needs to be emitted, as the guard always gets set by `__dyn_tls_init`.
The guard is also checked again within `__dyn_tls_init`. This makes our check redundant, however, as Microsoft's compiler also emits this check, the behaviour is adopted here.
Reviewed By: majnemer
Differential Revision: https://reviews.llvm.org/D115456
2022-01-13 10:26:30 +08:00
|
|
|
// CHECK-DAG: @__tls_guard = external dso_local thread_local global i8
|
2020-06-16 14:30:36 +08:00
|
|
|
// CHECK-LD-DAG: @"?b@@3UA@@A" = dso_local thread_local(localdynamic) global %struct.A zeroinitializer, align 1
|
|
|
|
// CHECK-LD-DAG: @"__tls_init$initializer$" = internal constant void ()* @__tls_init, section ".CRT$XDU"
|
[MS] Implement on-demand TLS initialization for Microsoft CXX ABI
TLS initializers, for example constructors of thread-local variables, don't necessarily get called. If a thread was created before a module is loaded, the module's TLS initializers are not executed for this particular thread.
This is why Microsoft added support for dynamic TLS initialization. Before every use of thread-local variables, a check is added that runs the module's TLS initializers on-demand.
To do this, the method `__dyn_tls_on_demand_init` gets called. Internally, it simply calls `__dyn_tls_init`.
No additional TLS initializer that sets the guard needs to be emitted, as the guard always gets set by `__dyn_tls_init`.
The guard is also checked again within `__dyn_tls_init`. This makes our check redundant, however, as Microsoft's compiler also emits this check, the behaviour is adopted here.
Reviewed By: majnemer
Differential Revision: https://reviews.llvm.org/D115456
2022-01-13 10:26:30 +08:00
|
|
|
// CHECK-LD-DAG: @__tls_guard = external dso_local thread_local global i8
|
|
|
|
// CHECK-LEGACY-NOT: @__tls_guard = external dso_local thread_local global i8
|
2014-10-05 13:05:40 +08:00
|
|
|
thread_local A b;
|
|
|
|
|
[MS] Implement on-demand TLS initialization for Microsoft CXX ABI
TLS initializers, for example constructors of thread-local variables, don't necessarily get called. If a thread was created before a module is loaded, the module's TLS initializers are not executed for this particular thread.
This is why Microsoft added support for dynamic TLS initialization. Before every use of thread-local variables, a check is added that runs the module's TLS initializers on-demand.
To do this, the method `__dyn_tls_on_demand_init` gets called. Internally, it simply calls `__dyn_tls_init`.
No additional TLS initializer that sets the guard needs to be emitted, as the guard always gets set by `__dyn_tls_init`.
The guard is also checked again within `__dyn_tls_init`. This makes our check redundant, however, as Microsoft's compiler also emits this check, the behaviour is adopted here.
Reviewed By: majnemer
Differential Revision: https://reviews.llvm.org/D115456
2022-01-13 10:26:30 +08:00
|
|
|
// CHECK-LABEL: declare dso_local void @__dyn_tls_on_demand_init()
|
|
|
|
// CHECK-LD-LABEL: declare dso_local void @__dyn_tls_on_demand_init()
|
|
|
|
// CHECK-LEGACY-NOT: declare dso_local void @__dyn_tls_on_demand_init()
|
|
|
|
|
|
|
|
// CHECK-LABEL: define dso_local void @"?f@@YA?AUA@@XZ"(%struct.A* noalias sret(%struct.A) align 1 %agg.result)
|
|
|
|
// CHECK: call void @__dyn_tls_on_demand_init()
|
|
|
|
// CHECK-LD-LABEL: define dso_local void @"?f@@YA?AUA@@XZ"(%struct.A* noalias sret(%struct.A) align 1 %agg.result)
|
|
|
|
// CHECK-LD: call void @__dyn_tls_on_demand_init()
|
|
|
|
// CHECK-LEGACY-NOT: call void @__dyn_tls_on_demand_init()
|
2014-10-05 13:05:40 +08:00
|
|
|
|
|
|
|
thread_local A &c = b;
|
|
|
|
thread_local A &d = c;
|
|
|
|
|
|
|
|
A f() {
|
|
|
|
(void)a<void>;
|
|
|
|
(void)b;
|
|
|
|
return c;
|
|
|
|
}
|
2016-09-12 10:51:43 +08:00
|
|
|
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK-LABEL: define dso_local noundef i32 @"?g@@YAHXZ"()
|
[MS] Implement on-demand TLS initialization for Microsoft CXX ABI
TLS initializers, for example constructors of thread-local variables, don't necessarily get called. If a thread was created before a module is loaded, the module's TLS initializers are not executed for this particular thread.
This is why Microsoft added support for dynamic TLS initialization. Before every use of thread-local variables, a check is added that runs the module's TLS initializers on-demand.
To do this, the method `__dyn_tls_on_demand_init` gets called. Internally, it simply calls `__dyn_tls_init`.
No additional TLS initializer that sets the guard needs to be emitted, as the guard always gets set by `__dyn_tls_init`.
The guard is also checked again within `__dyn_tls_init`. This makes our check redundant, however, as Microsoft's compiler also emits this check, the behaviour is adopted here.
Reviewed By: majnemer
Differential Revision: https://reviews.llvm.org/D115456
2022-01-13 10:26:30 +08:00
|
|
|
// CHECK-NOT: call void @__dyn_tls_on_demand_init()
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK-LD-LABEL: define dso_local noundef i32 @"?g@@YAHXZ"()
|
[MS] Implement on-demand TLS initialization for Microsoft CXX ABI
TLS initializers, for example constructors of thread-local variables, don't necessarily get called. If a thread was created before a module is loaded, the module's TLS initializers are not executed for this particular thread.
This is why Microsoft added support for dynamic TLS initialization. Before every use of thread-local variables, a check is added that runs the module's TLS initializers on-demand.
To do this, the method `__dyn_tls_on_demand_init` gets called. Internally, it simply calls `__dyn_tls_init`.
No additional TLS initializer that sets the guard needs to be emitted, as the guard always gets set by `__dyn_tls_init`.
The guard is also checked again within `__dyn_tls_init`. This makes our check redundant, however, as Microsoft's compiler also emits this check, the behaviour is adopted here.
Reviewed By: majnemer
Differential Revision: https://reviews.llvm.org/D115456
2022-01-13 10:26:30 +08:00
|
|
|
// CHECK-LD-NOT: call void @__dyn_tls_on_demand_init()
|
|
|
|
|
|
|
|
thread_local int e = 2;
|
|
|
|
|
|
|
|
int g() {
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: define internal void @__tls_init()
|
|
|
|
// CHECK: call void @"??__Eb@@YAXXZ"
|
|
|
|
// CHECK-LD-LABEL: define internal void @__tls_init()
|
|
|
|
// CHECK-LD: call void @"??__Eb@@YAXXZ"
|
|
|
|
|
2017-06-13 04:10:48 +08:00
|
|
|
// CHECK: !llvm.linker.options = !{![[dyn_tls_init:[0-9]+]]}
|
2016-09-12 10:51:43 +08:00
|
|
|
// CHECK: ![[dyn_tls_init]] = !{!"/include:___dyn_tls_init@12"}
|
2020-06-16 14:30:36 +08:00
|
|
|
// CHECK-LD: !llvm.linker.options = !{![[dyn_tls_init:[0-9]+]]}
|
|
|
|
// CHECK-LD: ![[dyn_tls_init]] = !{!"/include:___dyn_tls_init@12"}
|