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 {
56 typedef float HGVec4f __attribute__ ((vector_size(16)));
58 @interface RedBalloonHGXFormWrapper {
59 HGVec4f m_Transform[4];
63 @implementation RedBalloonHGXFormWrapper
66 namespace rdar9357400 {
67 template<int Dim1 = -1, int Dim2 = -1> struct fixed {
68 template<int D> struct rebind { typedef fixed<D> other; };
71 template<typename Element, int Size>
75 typedef Element value_type;
76 typedef value_type array_impl[Size];
81 template<typename Element, typename Alloc>
84 template<typename Element, int Size>
85 class vector< Element, fixed<Size> >
86 : public fixed_1D<Element,Size> { };
88 typedef vector< float, fixed<4> > vector4f;
90 // FIXME: This difference is due to D76801. It was probably an unintentional change. Maybe we want to undo it?
91 // @encoding for C++ is dependent on the TypePrinter implementation, which is a known issue. But since there
92 // are currently no system frameworks that vend Objective-C++ types, a potential ABI break caused by changes
93 // to the TypePrinter should not be a concern.
94 // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] c"{vector<float, rdar9357400::fixed<4> >=[4f]}\00"
95 // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] c"{vector<float, rdar9357400::fixed<4>>=[4f]}\00"
96 extern const char gg[] = @encode(vector4f);
99 namespace rdar9624314 {
100 struct B2 { int x; };
102 struct S : B2, B3 {};
104 // CHECK: @_ZN11rdar96243142ggE ={{.*}} constant [6 x i8] c"{S=i}\00"
105 extern const char gg[] = @encode(S);
107 struct S2 { unsigned : 0; int x; unsigned : 0; };
108 // CHECK: @_ZN11rdar96243142g2E ={{.*}} constant [11 x i8] c"{S2=b0ib0}\00"
109 extern const char g2[] = @encode(S2);
123 class Zoo : virtual public Foo, virtual public Bar {
129 // CHECK: @_ZN4test3ecdE ={{.*}} constant [15 x i8] c"{Zoo=^^?ii^^?}\00"
130 extern const char ecd[] = @encode(Zoo);
137 struct DBase : public Base1 {
142 struct Sub_with_virt : virtual DBase {
146 struct Sub2 : public Sub_with_virt, public Base1, virtual DBase {
150 // CHECK: @g1 ={{.*}} constant [10 x i8] c"{Base1=c}\00"
151 extern const char g1[] = @encode(Base1);
153 // CHECK: @g2 ={{.*}} constant [14 x i8] c"{DBase=^^?cd}\00"
154 extern const char g2[] = @encode(DBase);
156 // CHECK: @g3 ={{.*}} constant [26 x i8] c"{Sub_with_virt=^^?q^^?cd}\00"
157 extern const char g3[] = @encode(Sub_with_virt);
159 // CHECK: @g4 ={{.*}} constant [19 x i8] c"{Sub2=^^?qcf^^?cd}\00"
160 extern const char g4[] = @encode(Sub2);
162 // http://llvm.org/PR9927
166 struct _Alloc_hider : allocator {
169 _Alloc_hider _M_dataplus;
172 // CHECK: @g5 ={{.*}} constant [32 x i8] c"{basic_string={_Alloc_hider=*}}\00"
173 extern const char g5[] = @encode(basic_string);
178 virtual ~CefBase() {}
180 struct CefBrowser : public virtual CefBase {};
181 struct CefBrowserImpl : public CefBrowser {};
182 // CHECK: @g6 ={{.*}} constant [21 x i8] c"{CefBrowserImpl=^^?}\00"
183 extern const char g6[] = @encode(CefBrowserImpl);
187 virtual ~CefBase2() {}
190 struct CefBrowser2 : public virtual CefBase2 {};
191 struct CefBrowserImpl2 : public CefBrowser2 {};
192 // CHECK: @g7 ={{.*}} constant [26 x i8] c"{CefBrowserImpl2=^^?^^?i}\00"
193 extern const char g7[] = @encode(CefBrowserImpl2);
205 // CHECK: @g8 ={{.*}} constant [14 x i8] c"{Y={X=[10i]}}\00"
206 extern const char g8[] = @encode(Y);
209 class dynamic_class {
211 virtual ~dynamic_class();
213 @interface has_dynamic_class_ivar
215 @implementation has_dynamic_class_ivar {
216 dynamic_class dynamic_class_ivar;
219 // CHECK: private unnamed_addr constant [41 x i8] c"{dynamic_class=\22_vptr$dynamic_class\22^^?}\00"
222 struct A { virtual ~A(); };
223 struct B : virtual A { int y; };
224 struct C { virtual ~C(); int z; };
225 struct D : C, B { int a; };
227 // CHECK: @_ZN7PR171421xE ={{.*}} constant [14 x i8] c"{E=^^?i^^?ii}\00"
228 extern const char x[] = @encode(E);
231 // This test used to cause infinite recursion.
247 const char *expand_struct() {
248 // CHECK: @{{.*}} = private unnamed_addr constant [13 x i8] c"{N={S<N>=@}}\00"
252 #if __cplusplus >= 202002L
257 [[no_unique_address]] F n;
259 // CHECKCXX20: @_ZN7PR480481xE ={{.*}} constant [6 x i8] c"{I=i}\00"
260 extern const char x[] = @encode(I);
264 namespace test_cxx_template_specialization {
269 struct D0 : B0<int> {};
271 struct D2 : virtual B0<int> {};
286 typedef B0<int> *Array0[4];
300 // CHECK: @[[STR22:.*]] = {{.*}} [12 x i8] c"{B0<int>=i}\00"
301 // CHECK: @_ZN32test_cxx_template_specialization2b0E = global ptr @[[STR22]]
302 // CHECK-NO-TEMP-SPEC: @[[STR23:.*]] = {{.*}} [3 x i8] c"^v\00"
303 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization3b01E = global ptr @[[STR23]]
304 // CHECK-TEMP-SPEC: @[[STR23:.*]] = {{.*}} [13 x i8] c"^{B0<int>=i}\00"
305 // CHECK-TEMP-SPEC: @_ZN32test_cxx_template_specialization3b01E = global ptr @[[STR23]]
306 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization3b02E = global ptr @[[STR23]]
307 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2d0E = global ptr @[[STR23]]
308 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2d1E = global ptr @[[STR23]]
309 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2d2E = global ptr @[[STR23]]
310 // CHECK: @[[STR24:.*]] = {{.*}} [7 x i8] c"^^{D2}\00"
311 // CHECK: @_ZN32test_cxx_template_specialization3d21E = global ptr @[[STR24]]
312 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2s0E = global ptr @[[STR23]]
313 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2s1E = global ptr @[[STR23]]
314 // CHECK: @[[STR25:.*]] = {{.*}} [12 x i8] c"^{S2=^{S1}}\00"
315 // CHECK: @_ZN32test_cxx_template_specialization2s2E = global ptr @[[STR25]]
316 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2u0E = global ptr @[[STR23]]
317 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization3td0E = global ptr @[[STR23]]
318 // CHECK-NO-TEMP-SPEC: @[[STR26:.*]] = {{.*}} [6 x i8] c"[4^v]\00"
319 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization2a0E = global ptr @[[STR26]]
320 // CHECK: @[[STR27:.*]] = {{.*}} [11 x i8] c"^{Inner0=}\00"
321 // CHECK: @_ZN32test_cxx_template_specialization6inner0E = global ptr @[[STR27]]
322 // CHECK-NO-TEMP-SPEC: @_ZN32test_cxx_template_specialization6inner1E = global ptr @.str.23
323 // CHECK-TEMP-SPEC: @[[STR34:.*]] = {{.*}} [18 x i8] c"^{Inner1<float>=}\00"
324 // CHECK-TEMP-SPEC: @_ZN32test_cxx_template_specialization6inner1E = global ptr @[[STR34]]
326 const char *b0 = @encode(B0<int>);
327 const char *b01 = @encode(B0<int> *);
328 const char *b02 = @encode(B0<int> &);
329 const char *d0 = @encode(D0 *);
330 const char *d1 = @encode(D1 *);
331 const char *d2 = @encode(D2 *);
332 const char *d21 = @encode(D2 **);
333 const char *s0 = @encode(S0 *);
334 const char *s1 = @encode(S1 *);
335 const char *s2 = @encode(S2 *);
336 const char *u0 = @encode(U0<int> *);
337 const char *td0 = @encode(TD0 *);
338 const char *a0 = @encode(Array0);
339 const char *inner0 = @encode(Outer0<int>::Inner0 *);
340 const char *inner1 = @encode(Outer0<int>::Inner1<float> *);