1 // RUN: %clang_cc1 -Wno-objc-root-class -std=gnu++98 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck --check-prefixes CHECK,CHECKCXX98,CHECK-NO-TEMP-SPEC %s
2 // RUN: %clang_cc1 -Wno-objc-root-class -std=gnu++20 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck --check-prefixes CHECK,CHECKCXX20,CHECK-NO-TEMP-SPEC %s
3 // RUN: %clang_cc1 -Wno-objc-root-class -std=gnu++20 %s -triple=x86_64-apple-darwin10 -fobjc-encode-cxx-class-template-spec -emit-llvm -o - | FileCheck --check-prefixes CHECK,CHECKCXX20,CHECK-TEMP-SPEC %s
5 // CHECK: v17@0:8{vector<float, float, float>=}16
6 // CHECK: {vector<float, float, float>=}
9 template <typename T1, typename T2, typename T3> struct vector {
14 typedef vector< float, float, float > vector3f;
21 @property (assign, nonatomic) vector3f position;
25 @interface MyOpenGLView
30 @property vector3f position;
33 @implementation MyOpenGLView
39 vector3f VF3(1.0, 1.0, 1.0);
45 class Int3 { int x, y, z; };
47 // Enforce @encoding for member pointers.
49 - (void) foo: (int (Int3::*)) member;
51 @implementation MemPtr
52 - (void) foo: (int (Int3::*)) member {
57 typedef float HGVec4f __attribute__ ((vector_size(16)));
59 @interface RedBalloonHGXFormWrapper {
60 HGVec4f m_Transform[4];
64 @implementation RedBalloonHGXFormWrapper
68 namespace rdar9357400 {
69 template<int Dim1 = -1, int Dim2 = -1> struct fixed {
70 template<int D> struct rebind { typedef fixed<D> other; };
73 template<typename Element, int Size>
77 typedef Element value_type;
78 typedef value_type array_impl[Size];
83 template<typename Element, typename Alloc>
86 template<typename Element, int Size>
87 class vector< Element, fixed<Size> >
88 : public fixed_1D<Element,Size> { };
90 typedef vector< float, fixed<4> > vector4f;
92 // FIXME: This difference is due to D76801. It was probably an unintentional change. Maybe we want to undo it?
93 // @encoding for C++ is dependent on the TypePrinter implementation, which is a known issue. But since there
94 // are currently no system frameworks that vend Objective-C++ types, a potential ABI break caused by changes
95 // to the TypePrinter should not be a concern.
96 // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] c"{vector<float, rdar9357400::fixed<4> >=[4f]}\00"
97 // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] c"{vector<float, rdar9357400::fixed<4>>=[4f]}\00"
98 extern const char gg[] = @encode(vector4f);
102 namespace rdar9624314 {
103 struct B2 { int x; };
105 struct S : B2, B3 {};
107 // CHECK: @_ZN11rdar96243142ggE ={{.*}} constant [6 x i8] c"{S=i}\00"
108 extern const char gg[] = @encode(S);
110 struct S2 { unsigned : 0; int x; unsigned : 0; };
111 // CHECK: @_ZN11rdar96243142g2E ={{.*}} constant [11 x i8] c"{S2=b0ib0}\00"
112 extern const char g2[] = @encode(S2);
126 class Zoo : virtual public Foo, virtual public Bar {
132 // CHECK: @_ZN4test3ecdE ={{.*}} constant [15 x i8] c"{Zoo=^^?ii^^?}\00"
133 extern const char ecd[] = @encode(Zoo);
140 struct DBase : public Base1 {
145 struct Sub_with_virt : virtual DBase {
149 struct Sub2 : public Sub_with_virt, public Base1, virtual DBase {
153 // CHECK: @g1 ={{.*}} constant [10 x i8] c"{Base1=c}\00"
154 extern const char g1[] = @encode(Base1);
156 // CHECK: @g2 ={{.*}} constant [14 x i8] c"{DBase=^^?cd}\00"
157 extern const char g2[] = @encode(DBase);
159 // CHECK: @g3 ={{.*}} constant [26 x i8] c"{Sub_with_virt=^^?q^^?cd}\00"
160 extern const char g3[] = @encode(Sub_with_virt);
162 // CHECK: @g4 ={{.*}} constant [19 x i8] c"{Sub2=^^?qcf^^?cd}\00"
163 extern const char g4[] = @encode(Sub2);
165 // http://llvm.org/PR9927
169 struct _Alloc_hider : allocator {
172 _Alloc_hider _M_dataplus;
175 // CHECK: @g5 ={{.*}} constant [32 x i8] c"{basic_string={_Alloc_hider=*}}\00"
176 extern const char g5[] = @encode(basic_string);
181 virtual ~CefBase() {}
183 struct CefBrowser : public virtual CefBase {};
184 struct CefBrowserImpl : public CefBrowser {};
185 // CHECK: @g6 ={{.*}} constant [21 x i8] c"{CefBrowserImpl=^^?}\00"
186 extern const char g6[] = @encode(CefBrowserImpl);
190 virtual ~CefBase2() {}
193 struct CefBrowser2 : public virtual CefBase2 {};
194 struct CefBrowserImpl2 : public CefBrowser2 {};
195 // CHECK: @g7 ={{.*}} constant [26 x i8] c"{CefBrowserImpl2=^^?^^?i}\00"
196 extern const char g7[] = @encode(CefBrowserImpl2);
198 // <rdar://problem/11324167>
209 // CHECK: @g8 ={{.*}} constant [14 x i8] c"{Y={X=[10i]}}\00"
210 extern const char g8[] = @encode(Y);
213 class dynamic_class {
215 virtual ~dynamic_class();
217 @interface has_dynamic_class_ivar
219 @implementation has_dynamic_class_ivar {
220 dynamic_class dynamic_class_ivar;
223 // CHECK: private unnamed_addr constant [41 x i8] c"{dynamic_class=\22_vptr$dynamic_class\22^^?}\00"
226 struct A { virtual ~A(); };
227 struct B : virtual A { int y; };
228 struct C { virtual ~C(); int z; };
229 struct D : C, B { int a; };
231 // CHECK: @_ZN7PR171421xE ={{.*}} constant [14 x i8] c"{E=^^?i^^?ii}\00"
232 extern const char x[] = @encode(E);
235 // This test used to cause infinite recursion.
251 const char *expand_struct() {
252 // CHECK: @{{.*}} = private unnamed_addr constant [13 x i8] c"{N={S<N>=@}}\00"
256 #if __cplusplus >= 202002L
261 [[no_unique_address]] F n;
263 // CHECKCXX20: @_ZN7PR480481xE ={{.*}} constant [6 x i8] c"{I=i}\00"
264 extern const char x[] = @encode(I);
268 namespace test_cxx_template_specialization {
273 struct D0 : B0<int> {};
275 struct D2 : virtual B0<int> {};
290 typedef B0<int> *Array0[4];
304 // CHECK: @[[STR22:.*]] = {{.*}} [12 x i8] c"{B0<int>=i}\00"
305 // CHECK: @_ZN32test_cxx_template_specialization2b0E = global ptr @[[STR22]]
306 // CHECK-NO-TEMP-SPEC: @[[STR23:.*]] = {{.*}} [3 x i8] c"^v\00"
307 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization3b01E = global ptr @[[STR23]]
308 // CHECK-TEMP-SPEC: @[[STR23:.*]] = {{.*}} [13 x i8] c"^{B0<int>=i}\00"
309 // CHECK-TEMP-SPEC: @_ZN32test_cxx_template_specialization3b01E = global ptr @[[STR23]]
310 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization3b02E = global ptr @[[STR23]]
311 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2d0E = global ptr @[[STR23]]
312 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2d1E = global ptr @[[STR23]]
313 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2d2E = global ptr @[[STR23]]
314 // CHECK: @[[STR24:.*]] = {{.*}} [7 x i8] c"^^{D2}\00"
315 // CHECK: @_ZN32test_cxx_template_specialization3d21E = global ptr @[[STR24]]
316 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2s0E = global ptr @[[STR23]]
317 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2s1E = global ptr @[[STR23]]
318 // CHECK: @[[STR25:.*]] = {{.*}} [12 x i8] c"^{S2=^{S1}}\00"
319 // CHECK: @_ZN32test_cxx_template_specialization2s2E = global ptr @[[STR25]]
320 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2u0E = global ptr @[[STR23]]
321 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization3td0E = global ptr @[[STR23]]
322 // CHECK-NO-TEMP-SPEC: @[[STR26:.*]] = {{.*}} [6 x i8] c"[4^v]\00"
323 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2a0E = global ptr @[[STR26]]
324 // CHECK: @[[STR27:.*]] = {{.*}} [11 x i8] c"^{Inner0=}\00"
325 // CHECK: @_ZN32test_cxx_template_specialization6inner0E = global ptr @[[STR27]]
326 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization6inner1E = global ptr @.str.23
327 // CHECK-TEMP-SPEC: @[[STR34:.*]] = {{.*}} [18 x i8] c"^{Inner1<float>=}\00"
328 // CHECK-TEMP-SPEC: @_ZN32test_cxx_template_specialization6inner1E = global ptr @[[STR34]]
330 const char *b0 = @encode(B0<int>);
331 const char *b01 = @encode(B0<int> *);
332 const char *b02 = @encode(B0<int> &);
333 const char *d0 = @encode(D0 *);
334 const char *d1 = @encode(D1 *);
335 const char *d2 = @encode(D2 *);
336 const char *d21 = @encode(D2 **);
337 const char *s0 = @encode(S0 *);
338 const char *s1 = @encode(S1 *);
339 const char *s2 = @encode(S2 *);
340 const char *u0 = @encode(U0<int> *);
341 const char *td0 = @encode(TD0 *);
342 const char *a0 = @encode(Array0);
343 const char *inner0 = @encode(Outer0<int>::Inner0 *);
344 const char *inner1 = @encode(Outer0<int>::Inner1<float> *);