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