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