1 // RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-macosx10.7.0 -emit-llvm -o - %s | FileCheck %s 2 3 // CHECK: @_ZZNK7PR12917IJiiEE1nMUlvE_clEvE1n = linkonce_odr global i32 0 4 // CHECK: @_ZZN7PR12917IJicdEEC1EicdEd_N1nE = linkonce_odr global i32 0 5 // CHECK: @_ZZN7PR12917IJicdEEC1EicdEd0_N1nE = linkonce_odr global i32 0 6 // CHECK: @_ZZN7PR12917IJicdEEC1EicdEd1_N1nE = linkonce_odr global i32 0 7 8 // CHECK: define linkonce_odr void @_Z11inline_funci 9 inline void inline_func(int n) { 10 // CHECK: call i32 @_ZZ11inline_funciENKUlvE_clEv 11 int i = []{ return 1; }(); 12 13 // CHECK: call i32 @_ZZ11inline_funciENKUlvE0_clEv 14 int j = [=] { return n + i; }(); 15 16 // CHECK: call double @_ZZ11inline_funciENKUlvE1_clEv 17 int k = [=] () -> double { return n + i; }(); 18 19 // CHECK: call i32 @_ZZ11inline_funciENKUliE_clEi 20 int l = [=] (int x) -> int { return x + i; }(n); 21 22 int inner(int i = []{ return 17; }()); 23 // CHECK: call i32 @_ZZ11inline_funciENKUlvE2_clEv 24 // CHECK-NEXT: call i32 @_Z5inneri 25 inner(); 26 27 // CHECK-NEXT: ret void 28 } 29 30 void call_inline_func() { 31 inline_func(17); 32 } 33 34 struct S { 35 void f(int = []{return 1;}() 36 + []{return 2;}(), 37 int = []{return 3;}()); 38 void g(int, int); 39 }; 40 41 void S::g(int i = []{return 1;}(), 42 int j = []{return 2; }()) {} 43 44 // CHECK: define void @_Z6test_S1S 45 void test_S(S s) { 46 // CHECK: call i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv 47 // CHECK-NEXT: call i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv 48 // CHECK-NEXT: add nsw i32 49 // CHECK-NEXT: call i32 @_ZZN1S1fEiiEd_NKUlvE_clEv 50 // CHECK-NEXT: call void @_ZN1S1fEii 51 s.f(); 52 53 // NOTE: These manglings don't actually matter that much, because 54 // the lambdas in the default arguments of g() won't be seen by 55 // multiple translation units. We check them mainly to ensure that they don't 56 // get the special mangling for lambdas in in-class default arguments. 57 // CHECK: call i32 @"_ZNK1S3$_0clEv" 58 // CHECK-NEXT: call i32 @"_ZNK1S3$_1clEv" 59 // CHECK-NEXT: call void @_ZN1S1gEi 60 s.g(); 61 62 // CHECK-NEXT: ret void 63 } 64 65 // Check the linkage of the lambda call operators used in test_S. 66 // CHECK: define linkonce_odr i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv 67 // CHECK: ret i32 1 68 // CHECK: define linkonce_odr i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv 69 // CHECK: ret i32 2 70 // CHECK: define linkonce_odr i32 @_ZZN1S1fEiiEd_NKUlvE_clEv 71 // CHECK: ret i32 3 72 // CHECK: define internal i32 @"_ZNK1S3$_0clEv" 73 // CHECK: ret i32 1 74 // CHECK: define internal i32 @"_ZNK1S3$_1clEv" 75 // CHECK: ret i32 2 76 77 template<typename T> 78 struct ST { 79 void f(T = []{return T() + 1;}() 80 + []{return T() + 2;}(), 81 T = []{return T(3);}()); 82 }; 83 84 // CHECK: define void @_Z7test_ST2STIdE 85 void test_ST(ST<double> st) { 86 // CHECK: call double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv 87 // CHECK-NEXT: call double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv 88 // CHECK-NEXT: fadd double 89 // CHECK-NEXT: call double @_ZZN2STIdE1fEddEd_NKUlvE_clEv 90 // CHECK-NEXT: call void @_ZN2STIdE1fEdd 91 st.f(); 92 93 // CHECK-NEXT: ret void 94 } 95 96 // Check the linkage of the lambda call operators used in test_ST. 97 // CHECK: define linkonce_odr double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv 98 // CHECK: ret double 1 99 // CHECK: define linkonce_odr double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv 100 // CHECK: ret double 2 101 // CHECK: define linkonce_odr double @_ZZN2STIdE1fEddEd_NKUlvE_clEv 102 // CHECK: ret double 3 103 104 template<typename T> 105 struct StaticMembers { 106 static T x; 107 static T y; 108 static T z; 109 }; 110 111 template<typename T> int accept_lambda(T); 112 113 template<typename T> 114 T StaticMembers<T>::x = []{return 1;}() + []{return 2;}(); 115 116 template<typename T> 117 T StaticMembers<T>::y = []{return 3;}(); 118 119 template<typename T> 120 T StaticMembers<T>::z = accept_lambda([]{return 4;}); 121 122 // CHECK: define internal void @__cxx_global_var_init() 123 // CHECK: call i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv 124 // CHECK-NEXT: call i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv 125 // CHECK-NEXT: add nsw 126 // CHECK: define linkonce_odr i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv 127 // CHECK: ret i32 1 128 // CHECK: define linkonce_odr i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv 129 // CHECK: ret i32 2 130 template float StaticMembers<float>::x; 131 132 // CHECK: define internal void @__cxx_global_var_init1() 133 // CHECK: call i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv 134 // CHECK: define linkonce_odr i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv 135 // CHECK: ret i32 3 136 template float StaticMembers<float>::y; 137 138 // CHECK: define internal void @__cxx_global_var_init2() 139 // CHECK: call i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_ 140 // CHECK: declare i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_() 141 template float StaticMembers<float>::z; 142 143 // CHECK: define internal void @__cxx_global_var_init3 144 // CHECK: call i32 @"_ZNK13StaticMembersIdE3$_2clEv" 145 // CHECK: define internal i32 @"_ZNK13StaticMembersIdE3$_2clEv" 146 // CHECK: ret i32 42 147 template<> double StaticMembers<double>::z = []{return 42; }(); 148 149 template<typename T> 150 void func_template(T = []{ return T(); }()); 151 152 // CHECK: define void @_Z17use_func_templatev() 153 void use_func_template() { 154 // CHECK: call i32 @"_ZZ13func_templateIiEvT_ENKS_IiE3$_3clEv" 155 func_template<int>(); 156 } 157 158 159 template<typename...T> struct PR12917 { 160 PR12917(T ...t = []{ static int n = 0; return ++n; }()); 161 162 static int n[3]; 163 }; 164 template<typename...T> int PR12917<T...>::n[3] = { 165 []{ static int n = 0; return ++n; }() 166 }; 167 168 // CHECK: call i32 @_ZZN7PR12917IJicdEEC1EicdEd1_NKUlvE_clEv( 169 // CHECK: call i32 @_ZZN7PR12917IJicdEEC1EicdEd0_NKUlvE_clEv( 170 // CHECK: call i32 @_ZZN7PR12917IJicdEEC1EicdEd_NKUlvE_clEv( 171 // CHECK: call void @_ZN7PR12917IJicdEEC1Eicd( 172 PR12917<int, char, double> pr12917; 173 int *pr12917_p = PR12917<int, int>::n; 174 175 176 // CHECK: define linkonce_odr void @_Z1fIZZNK23TestNestedInstantiationclEvENKUlvE_clEvEUlvE_EvT_ 177 178 struct Members { 179 int x = [] { return 1; }() + [] { return 2; }(); 180 int y = [] { return 3; }(); 181 }; 182 183 void test_Members() { 184 // CHECK: define linkonce_odr void @_ZN7MembersC2Ev 185 // CHECK: call i32 @_ZNK7Members1xMUlvE_clEv 186 // CHECK-NEXT: call i32 @_ZNK7Members1xMUlvE0_clE 187 // CHECK-NEXT: add nsw i32 188 // CHECK: call i32 @_ZNK7Members1yMUlvE_clEv 189 Members members; 190 // CHECK: ret void 191 } 192 193 template<typename P> void f(P) { } 194 195 struct TestNestedInstantiation { 196 void operator()() const { 197 []() -> void { 198 return f([]{}); 199 }(); 200 } 201 }; 202 203 void test_NestedInstantiation() { 204 TestNestedInstantiation()(); 205 } 206 207 // Check the linkage of the lambdas used in test_Members. 208 // CHECK: define linkonce_odr i32 @_ZNK7Members1xMUlvE_clEv 209 // CHECK: ret i32 1 210 // CHECK: define linkonce_odr i32 @_ZNK7Members1xMUlvE0_clEv 211 // CHECK: ret i32 2 212 // CHECK: define linkonce_odr i32 @_ZNK7Members1yMUlvE_clEv 213 // CHECK: ret i32 3 214 215 // Check linkage of the various lambdas. 216 // CHECK: define linkonce_odr i32 @_ZZ11inline_funciENKUlvE_clEv 217 // CHECK: ret i32 1 218 // CHECK: define linkonce_odr i32 @_ZZ11inline_funciENKUlvE0_clEv 219 // CHECK: ret i32 220 // CHECK: define linkonce_odr double @_ZZ11inline_funciENKUlvE1_clEv 221 // CHECK: ret double 222 // CHECK: define linkonce_odr i32 @_ZZ11inline_funciENKUliE_clEi 223 // CHECK: ret i32 224 // CHECK: define linkonce_odr i32 @_ZZ11inline_funciENKUlvE2_clEv 225 // CHECK: ret i32 17 226