1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 %s -std=c++1y -triple=x86_64-pc-linux -emit-llvm -o - | FileCheck --check-prefix=ELF --check-prefix=ALL %s 2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 %s -std=c++1y -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck --check-prefix=MACHO --check-prefix=ALL %s 3*0a6a1f1dSLionel Sambuc 4*0a6a1f1dSLionel Sambuc // ALL: ; ModuleID 5f4a2713aSLionel Sambuc 6f4a2713aSLionel Sambuc extern "C" int foo(); 7f4a2713aSLionel Sambuc 8f4a2713aSLionel Sambuc template<typename T> struct A { static int a; }; 9f4a2713aSLionel Sambuc template<typename T> int A<T>::a = foo(); 10f4a2713aSLionel Sambuc 11*0a6a1f1dSLionel Sambuc // ALLK-NOT: @_ZN1AIcE1aE 12f4a2713aSLionel Sambuc template<> int A<char>::a; 13f4a2713aSLionel Sambuc 14*0a6a1f1dSLionel Sambuc // ALL: @_ZN1AIbE1aE = global i32 10 15f4a2713aSLionel Sambuc template<> int A<bool>::a = 10; 16f4a2713aSLionel Sambuc 17*0a6a1f1dSLionel Sambuc // ALL: @llvm.global_ctors = appending global [8 x { i32, void ()*, i8* }] 18*0a6a1f1dSLionel Sambuc 19*0a6a1f1dSLionel Sambuc // ELF: [{ i32, void ()*, i8* } { i32 65535, void ()* @[[unordered1:[^,]*]], i8* bitcast (i32* @_ZN1AIsE1aE to i8*) }, 20*0a6a1f1dSLionel Sambuc // MACHO: [{ i32, void ()*, i8* } { i32 65535, void ()* @[[unordered1:[^,]*]], i8* null }, 21*0a6a1f1dSLionel Sambuc 22*0a6a1f1dSLionel Sambuc // ELF: { i32, void ()*, i8* } { i32 65535, void ()* @[[unordered2:[^,]*]], i8* bitcast (i16* @_Z1xIsE to i8*) }, 23*0a6a1f1dSLionel Sambuc // MACHO: { i32, void ()*, i8* } { i32 65535, void ()* @[[unordered2:[^,]*]], i8* null }, 24*0a6a1f1dSLionel Sambuc 25*0a6a1f1dSLionel Sambuc // ELF: { i32, void ()*, i8* } { i32 65535, void ()* @[[unordered3:[^,]*]], i8* bitcast (i32* @_ZN2ns1aIiE1iE to i8*) }, 26*0a6a1f1dSLionel Sambuc // MACHO: { i32, void ()*, i8* } { i32 65535, void ()* @[[unordered3:[^,]*]], i8* null }, 27*0a6a1f1dSLionel Sambuc 28*0a6a1f1dSLionel Sambuc // ELF: { i32, void ()*, i8* } { i32 65535, void ()* @[[unordered4:[^,]*]], i8* bitcast (i32* @_ZN2ns1b1iIiEE to i8*) }, 29*0a6a1f1dSLionel Sambuc // MACHO: { i32, void ()*, i8* } { i32 65535, void ()* @[[unordered4:[^,]*]], i8* null }, 30*0a6a1f1dSLionel Sambuc 31*0a6a1f1dSLionel Sambuc // ELF: { i32, void ()*, i8* } { i32 65535, void ()* @[[unordered5:[^,]*]], i8* bitcast (i32* @_ZN1AIvE1aE to i8*) }, 32*0a6a1f1dSLionel Sambuc // MACHO: { i32, void ()*, i8* } { i32 65535, void ()* @[[unordered5:[^,]*]], i8* null }, 33*0a6a1f1dSLionel Sambuc 34*0a6a1f1dSLionel Sambuc // ELF: { i32, void ()*, i8* } { i32 65535, void ()* @[[unordered6:[^,]*]], i8* @_Z1xIcE }, 35*0a6a1f1dSLionel Sambuc // MACHO: { i32, void ()*, i8* } { i32 65535, void ()* @[[unordered6:[^,]*]], i8* null }, 36*0a6a1f1dSLionel Sambuc 37*0a6a1f1dSLionel Sambuc // ALL: { i32, void ()*, i8* } { i32 65535, void ()* @[[unordered7:[^,]*]], i8* null }, 38*0a6a1f1dSLionel Sambuc 39*0a6a1f1dSLionel Sambuc // ALL: { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_static_member_variable_explicit_specialization.cpp, i8* null }] 40f4a2713aSLionel Sambuc 41f4a2713aSLionel Sambuc template int A<short>::a; // Unordered 42f4a2713aSLionel Sambuc int b = foo(); 43f4a2713aSLionel Sambuc int c = foo(); 44f4a2713aSLionel Sambuc int d = A<void>::a; // Unordered 45f4a2713aSLionel Sambuc 46*0a6a1f1dSLionel Sambuc // An explicit specialization is ordered, and goes in __GLOBAL_sub_I_static_member_variable_explicit_specialization.cpp. 47f4a2713aSLionel Sambuc template<> struct A<int> { static int a; }; 48f4a2713aSLionel Sambuc int A<int>::a = foo(); 49f4a2713aSLionel Sambuc 50f4a2713aSLionel Sambuc template<typename T> struct S { static T x; static T y; }; 51f4a2713aSLionel Sambuc template<> int S<int>::x = foo(); 52f4a2713aSLionel Sambuc template<> int S<int>::y = S<int>::x; 53f4a2713aSLionel Sambuc 54f4a2713aSLionel Sambuc template<typename T> T x = foo(); 55f4a2713aSLionel Sambuc template short x<short>; // Unordered 56f4a2713aSLionel Sambuc template<> int x<int> = foo(); 57f4a2713aSLionel Sambuc int e = x<char>; // Unordered 58f4a2713aSLionel Sambuc 59f4a2713aSLionel Sambuc namespace ns { 60f4a2713aSLionel Sambuc template <typename T> struct a { 61f4a2713aSLionel Sambuc static int i; 62f4a2713aSLionel Sambuc }; 63f4a2713aSLionel Sambuc template<typename T> int a<T>::i = foo(); 64f4a2713aSLionel Sambuc template struct a<int>; 65f4a2713aSLionel Sambuc 66f4a2713aSLionel Sambuc struct b { 67f4a2713aSLionel Sambuc template <typename T> static T i; 68f4a2713aSLionel Sambuc }; 69f4a2713aSLionel Sambuc template<typename T> T b::i = foo(); 70f4a2713aSLionel Sambuc template int b::i<int>; 71f4a2713aSLionel Sambuc } 72f4a2713aSLionel Sambuc 73*0a6a1f1dSLionel Sambuc namespace { 74*0a6a1f1dSLionel Sambuc template<typename T> struct Internal { static int a; }; 75*0a6a1f1dSLionel Sambuc template<typename T> int Internal<T>::a = foo(); 76*0a6a1f1dSLionel Sambuc } 77*0a6a1f1dSLionel Sambuc int *use_internal_a = &Internal<int>::a; 78f4a2713aSLionel Sambuc 79*0a6a1f1dSLionel Sambuc // ALL: define internal void @[[unordered1]]( 80*0a6a1f1dSLionel Sambuc // ALL: call i32 @foo() 81*0a6a1f1dSLionel Sambuc // ALL: store {{.*}} @_ZN1AIsE1aE 82*0a6a1f1dSLionel Sambuc // ALL: ret 83f4a2713aSLionel Sambuc 84*0a6a1f1dSLionel Sambuc // ALL: define internal void @[[unordered2]]( 85*0a6a1f1dSLionel Sambuc // ALL: call i32 @foo() 86*0a6a1f1dSLionel Sambuc // ALL: store {{.*}} @_Z1xIsE 87*0a6a1f1dSLionel Sambuc // ALL: ret 88f4a2713aSLionel Sambuc 89*0a6a1f1dSLionel Sambuc // ALL: define internal void @[[unordered3]]( 90*0a6a1f1dSLionel Sambuc // ALL: call i32 @foo() 91*0a6a1f1dSLionel Sambuc // ALL: store {{.*}} @_ZN2ns1aIiE1iE 92*0a6a1f1dSLionel Sambuc // ALL: ret 93f4a2713aSLionel Sambuc 94*0a6a1f1dSLionel Sambuc // ALL: define internal void @[[unordered4]]( 95*0a6a1f1dSLionel Sambuc // ALL: call i32 @foo() 96*0a6a1f1dSLionel Sambuc // ALL: store {{.*}} @_ZN2ns1b1iIiEE 97*0a6a1f1dSLionel Sambuc // ALL: ret 98f4a2713aSLionel Sambuc 99*0a6a1f1dSLionel Sambuc // ALL: define internal void @[[unordered5]]( 100*0a6a1f1dSLionel Sambuc // ALL: call i32 @foo() 101*0a6a1f1dSLionel Sambuc // ALL: store {{.*}} @_ZN1AIvE1aE 102*0a6a1f1dSLionel Sambuc // ALL: ret 103*0a6a1f1dSLionel Sambuc 104*0a6a1f1dSLionel Sambuc // ALL: define internal void @[[unordered6]]( 105*0a6a1f1dSLionel Sambuc // ALL: call i32 @foo() 106*0a6a1f1dSLionel Sambuc // ALL: store {{.*}} @_Z1xIcE 107*0a6a1f1dSLionel Sambuc // ALL: ret 108*0a6a1f1dSLionel Sambuc 109*0a6a1f1dSLionel Sambuc // ALL: define internal void @[[unordered7]]( 110*0a6a1f1dSLionel Sambuc // ALL: call i32 @foo() 111*0a6a1f1dSLionel Sambuc // ALL: store {{.*}} @_ZN12_GLOBAL__N_18InternalIiE1aE 112*0a6a1f1dSLionel Sambuc // ALL: ret 113*0a6a1f1dSLionel Sambuc 114*0a6a1f1dSLionel Sambuc // ALL: define internal void @_GLOBAL__sub_I_static_member_variable_explicit_specialization.cpp() 115f4a2713aSLionel Sambuc // We call unique stubs for every ordered dynamic initializer in the TU. 116*0a6a1f1dSLionel Sambuc // ALL: call 117*0a6a1f1dSLionel Sambuc // ALL: call 118*0a6a1f1dSLionel Sambuc // ALL: call 119*0a6a1f1dSLionel Sambuc // ALL: call 120*0a6a1f1dSLionel Sambuc // ALL: call 121*0a6a1f1dSLionel Sambuc // ALL: call 122*0a6a1f1dSLionel Sambuc // ALL: call 123*0a6a1f1dSLionel Sambuc // ALL: call 124*0a6a1f1dSLionel Sambuc // ALL-NOT: call 125*0a6a1f1dSLionel Sambuc // ALL: ret 126