1 // RUN: %clang_cc1 %s -triple=i686-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s
5 // CHECK: $"?x@selectany_init@@3HA" = comdat any
6 // CHECK: $"?x@?$A@H@explicit_template_instantiation@@2HB" = comdat any
7 // CHECK: $"?x@?$A@H@implicit_template_instantiation@@2HB" = comdat any
9 namespace simple_init
{
10 #pragma init_seg(compiler)
12 // CHECK: @"?x@simple_init@@3HA" = dso_local global i32 0, align 4
13 // No function pointer! This one goes on @llvm.global_ctors.
17 // CHECK: @"?y@simple_init@@3HA" = dso_local global i32 0, align 4
18 // No function pointer! This one goes on @llvm.global_ctors.
20 #pragma init_seg(user)
22 // CHECK: @"?z@simple_init@@3HA" = dso_local global i32 0, align 4
23 // No function pointer! This one goes on @llvm.global_ctors.
26 #pragma init_seg(".asdf")
28 namespace internal_init
{
31 // CHECK: @"?x@?A0x{{[^@]*}}@internal_init@@3HA" = internal global i32 0, align 4
32 // CHECK: @__cxx_init_fn_ptr = private constant ptr @"??__Ex@?A0x{{[^@]*}}@internal_init@@YAXXZ", section ".asdf"
36 namespace selectany_init
{
37 int __declspec(selectany
) x
= f();
38 // CHECK: @"?x@selectany_init@@3HA" = weak_odr dso_local global i32 0, comdat, align 4
39 // CHECK: @__cxx_init_fn_ptr.1 = private constant ptr @"??__Ex@selectany_init@@YAXXZ", section ".asdf", comdat($"?x@selectany_init@@3HA")
42 namespace explicit_template_instantiation
{
43 template <typename T
> struct A
{ static const int x
; };
44 template <typename T
> const int A
<T
>::x
= f();
45 template struct A
<int>;
46 // CHECK: @"?x@?$A@H@explicit_template_instantiation@@2HB" = weak_odr dso_local global i32 0, comdat, align 4
47 // CHECK: @__cxx_init_fn_ptr.2 = private constant ptr @"??__E?x@?$A@H@explicit_template_instantiation@@2HB@@YAXXZ", section ".asdf", comdat($"?x@?$A@H@explicit_template_instantiation@@2HB")
50 namespace implicit_template_instantiation
{
51 template <typename T
> struct A
{ static const int x
; };
52 template <typename T
> const int A
<T
>::x
= f();
53 int g() { return A
<int>::x
; }
54 // CHECK: @"?x@?$A@H@implicit_template_instantiation@@2HB" = linkonce_odr dso_local global i32 0, comdat, align 4
55 // CHECK: @__cxx_init_fn_ptr.3 = private constant ptr @"??__E?x@?$A@H@implicit_template_instantiation@@2HB@@YAXXZ", section ".asdf", comdat($"?x@?$A@H@implicit_template_instantiation@@2HB")
58 // ... and here's where we emitted user level ctors.
59 // CHECK: @llvm.global_ctors = appending global [3 x { i32, ptr, ptr }]
60 // CHECK: [{ i32, ptr, ptr } { i32 200, ptr @"??__Ex@simple_init@@YAXXZ", ptr @"?x@simple_init@@3HA" }, { i32, ptr, ptr } { i32 400, ptr @"??__Ey@simple_init@@YAXXZ", ptr @"?y@simple_init@@3HA" }, { i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_pragma_init_seg.cpp, ptr null }]
62 // We have to mark everything used so we can survive globalopt, even through
63 // LTO. There's no way LLVM could really understand if data in the .asdf
64 // section is really used or dead.
66 // CHECK: @llvm.used = appending global [4 x ptr]
67 // CHECK: [ptr @__cxx_init_fn_ptr,
68 // CHECK: ptr @__cxx_init_fn_ptr.1,
69 // CHECK: ptr @__cxx_init_fn_ptr.2,
70 // CHECK: ptr @__cxx_init_fn_ptr.3], section "llvm.metadata"