xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjC/encode-test.m (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple i686-apple-darwin9 -fobjc-runtime=macosx-fragile-10.5 -emit-llvm -o %t %s
2f4a2713aSLionel Sambuc// RUN: FileCheck < %t %s
3f4a2713aSLionel Sambuc//
4*0a6a1f1dSLionel Sambuc// CHECK: @OBJC_METH_VAR_TYPE_34 = private global [16 x i8] c"v12@0:4[3[4@]]8\00"
5f4a2713aSLionel Sambuc
6f4a2713aSLionel Sambuc@class Int1;
7f4a2713aSLionel Sambuc
8f4a2713aSLionel Sambucstruct Innermost {
9f4a2713aSLionel Sambuc  unsigned char a, b;
10f4a2713aSLionel Sambuc};
11f4a2713aSLionel Sambuc
12f4a2713aSLionel Sambuc@interface Int1 {
13f4a2713aSLionel Sambuc  signed char a, b;
14f4a2713aSLionel Sambuc  struct Innermost *innermost;
15f4a2713aSLionel Sambuc}
16f4a2713aSLionel Sambuc@end
17f4a2713aSLionel Sambuc
18f4a2713aSLionel Sambuc@implementation Int1
19f4a2713aSLionel Sambuc@end
20f4a2713aSLionel Sambuc
21f4a2713aSLionel Sambuc@interface Base
22f4a2713aSLionel Sambuc{
23f4a2713aSLionel Sambuc    struct objc_class *isa;
24f4a2713aSLionel Sambuc    int full;
25f4a2713aSLionel Sambuc    int full2: 32;
26f4a2713aSLionel Sambuc    int _refs: 8;
27f4a2713aSLionel Sambuc    int field2: 3;
28f4a2713aSLionel Sambuc    unsigned f3: 8;
29f4a2713aSLionel Sambuc    short cc;
30f4a2713aSLionel Sambuc    unsigned g: 16;
31f4a2713aSLionel Sambuc    int r2: 8;
32f4a2713aSLionel Sambuc    int r3: 8;
33f4a2713aSLionel Sambuc    int r4: 2;
34f4a2713aSLionel Sambuc    int r5: 8;
35f4a2713aSLionel Sambuc    char c;
36f4a2713aSLionel Sambuc}
37f4a2713aSLionel Sambuc@end
38f4a2713aSLionel Sambuc
39f4a2713aSLionel Sambuc@interface Derived: Base
40f4a2713aSLionel Sambuc{
41f4a2713aSLionel Sambuc    char d;
42f4a2713aSLionel Sambuc    int _field3: 6;
43f4a2713aSLionel Sambuc}
44f4a2713aSLionel Sambuc@end
45f4a2713aSLionel Sambuc
46f4a2713aSLionel Sambuc@implementation Base
47f4a2713aSLionel Sambuc@end
48f4a2713aSLionel Sambuc
49f4a2713aSLionel Sambuc@implementation Derived
50f4a2713aSLionel Sambuc@end
51f4a2713aSLionel Sambuc
52f4a2713aSLionel Sambuc@interface B1
53f4a2713aSLionel Sambuc{
54f4a2713aSLionel Sambuc    struct objc_class *isa;
55f4a2713aSLionel Sambuc    Int1 *sBase;
56f4a2713aSLionel Sambuc    char c;
57f4a2713aSLionel Sambuc}
58f4a2713aSLionel Sambuc@end
59f4a2713aSLionel Sambuc
60f4a2713aSLionel Sambuc@implementation B1
61f4a2713aSLionel Sambuc@end
62f4a2713aSLionel Sambuc
63f4a2713aSLionel Sambuc@interface Test
64f4a2713aSLionel Sambuc{
65f4a2713aSLionel Sambuc	int ivar;
66f4a2713aSLionel Sambuc         __attribute__((objc_gc(weak))) SEL selector;
67f4a2713aSLionel Sambuc}
68f4a2713aSLionel Sambuc-(void) test3: (Test*  [3] [4])b ;
69f4a2713aSLionel Sambuc- (SEL**) meth : (SEL) arg : (SEL*****) arg1 : (SEL*)arg2 : (SEL**) arg3;
70f4a2713aSLionel Sambuc@end
71f4a2713aSLionel Sambuc
72f4a2713aSLionel Sambuc@implementation Test
73f4a2713aSLionel Sambuc-(void) test3: (Test* [3] [4])b {}
74f4a2713aSLionel Sambuc- (SEL**) meth : (SEL) arg : (SEL*****) arg1 : (SEL*)arg2 : (SEL**) arg3 {}
75f4a2713aSLionel Sambuc@end
76f4a2713aSLionel Sambuc
77f4a2713aSLionel Sambucstruct S { int iS; };
78f4a2713aSLionel Sambuc
79f4a2713aSLionel Sambuc@interface Object
80f4a2713aSLionel Sambuc{
81f4a2713aSLionel Sambuc Class isa;
82f4a2713aSLionel Sambuc}
83f4a2713aSLionel Sambuc@end
84f4a2713aSLionel Sambuctypedef Object MyObj;
85f4a2713aSLionel Sambuc
86f4a2713aSLionel Sambucint main()
87f4a2713aSLionel Sambuc{
88f4a2713aSLionel Sambuc	const char *en = @encode(Derived);
89f4a2713aSLionel Sambuc	const char *eb = @encode(B1);
90f4a2713aSLionel Sambuc        const char *es = @encode(const struct S *);
91f4a2713aSLionel Sambuc        const char *ec = @encode(const struct S);
92f4a2713aSLionel Sambuc        const char *ee = @encode(MyObj *const);
93f4a2713aSLionel Sambuc}
94f4a2713aSLionel Sambuc
95f4a2713aSLionel Sambuc// CHECK: @g0 = constant [15 x i8] c"{Innermost=CC}\00"
96f4a2713aSLionel Sambucconst char g0[] = @encode(struct Innermost);
97f4a2713aSLionel Sambuc
98f4a2713aSLionel Sambuc// CHECK: @g1 = constant [38 x i8] c"{Derived=#ib32b8b3b8sb16b8b8b2b8ccb6}\00"
99f4a2713aSLionel Sambucconst char g1[] = @encode(Derived);
100f4a2713aSLionel Sambuc
101f4a2713aSLionel Sambuc// CHECK: @g2 = constant [9 x i8] c"{B1=#@c}\00"
102f4a2713aSLionel Sambucconst char g2[] = @encode(B1);
103f4a2713aSLionel Sambuc
104f4a2713aSLionel Sambuc// CHECK: @g3 = constant [8 x i8] c"r^{S=i}\00"
105f4a2713aSLionel Sambucconst char g3[] = @encode(const struct S *);
106f4a2713aSLionel Sambuc
107f4a2713aSLionel Sambuc// CHECK: @g4 = constant [6 x i8] c"{S=i}\00"
108f4a2713aSLionel Sambucconst char g4[] = @encode(const struct S);
109f4a2713aSLionel Sambuc
110f4a2713aSLionel Sambuc// CHECK: @g5 = constant [12 x i8] c"^{Object=#}\00"
111f4a2713aSLionel Sambucconst char g5[] = @encode(MyObj * const);
112f4a2713aSLionel Sambuc
113f4a2713aSLionel Sambuc////
114f4a2713aSLionel Sambuc
115f4a2713aSLionel Sambucenum Enum1X { one, two, three, four };
116f4a2713aSLionel Sambuc
117f4a2713aSLionel Sambuc@interface Base1X {
118f4a2713aSLionel Sambuc  unsigned a: 2;
119f4a2713aSLionel Sambuc  int b: 3;
120f4a2713aSLionel Sambuc  enum Enum1X c: 4;
121f4a2713aSLionel Sambuc  unsigned d: 5;
122f4a2713aSLionel Sambuc}
123f4a2713aSLionel Sambuc@end
124f4a2713aSLionel Sambuc
125f4a2713aSLionel Sambuc@interface Derived1X: Base1X {
126f4a2713aSLionel Sambuc  signed e: 5;
127f4a2713aSLionel Sambuc  int f: 4;
128f4a2713aSLionel Sambuc  enum Enum1X g: 3;
129f4a2713aSLionel Sambuc}
130f4a2713aSLionel Sambuc@end
131f4a2713aSLionel Sambuc
132f4a2713aSLionel Sambuc@implementation Base1X @end
133f4a2713aSLionel Sambuc
134f4a2713aSLionel Sambuc@implementation Derived1X @end
135f4a2713aSLionel Sambuc
136f4a2713aSLionel Sambuc// CHECK: @g6 = constant [18 x i8] c"{Base1X=b2b3b4b5}\00"
137f4a2713aSLionel Sambucconst char g6[] = @encode(Base1X);
138f4a2713aSLionel Sambuc
139f4a2713aSLionel Sambuc// CHECK: @g7 = constant [27 x i8] c"{Derived1X=b2b3b4b5b5b4b3}\00"
140f4a2713aSLionel Sambucconst char g7[] = @encode(Derived1X);
141f4a2713aSLionel Sambuc
142f4a2713aSLionel Sambuc// CHECK: @g8 = constant [7 x i8] c"{s8=D}\00"
143f4a2713aSLionel Sambucstruct s8 {
144f4a2713aSLionel Sambuc  long double x;
145f4a2713aSLionel Sambuc};
146f4a2713aSLionel Sambucconst char g8[] = @encode(struct s8);
147f4a2713aSLionel Sambuc
148f4a2713aSLionel Sambuc// CHECK: @g9 = constant [11 x i8] c"{S9=i[0i]}\00"
149f4a2713aSLionel Sambucstruct S9 {
150f4a2713aSLionel Sambuc  int x;
151f4a2713aSLionel Sambuc  int flex[];
152f4a2713aSLionel Sambuc};
153f4a2713aSLionel Sambucconst char g9[] = @encode(struct S9);
154f4a2713aSLionel Sambuc
155f4a2713aSLionel Sambucstruct f
156f4a2713aSLionel Sambuc{
157f4a2713aSLionel Sambuc  int i;
158f4a2713aSLionel Sambuc  struct{} g[4];
159f4a2713aSLionel Sambuc  int tt;
160f4a2713aSLionel Sambuc};
161f4a2713aSLionel Sambuc
162f4a2713aSLionel Sambuc// CHECK: @g10 = constant [14 x i8] c"{f=i[4{?=}]i}\00"
163f4a2713aSLionel Sambucconst char g10[] = @encode(struct f);
164f4a2713aSLionel Sambuc
165f4a2713aSLionel Sambuc// rdar://9622422
166f4a2713aSLionel Sambuc// CHECK: @g11 = constant [2 x i8] c"v\00"
167f4a2713aSLionel Sambucconst char g11[] = @encode(void);
168f4a2713aSLionel Sambuc
169f4a2713aSLionel Sambuc// PR14628
170f4a2713aSLionel Sambuc// CHECK: @g12 = constant [3 x i8] c"Ai\00"
171f4a2713aSLionel Sambucconst char g12[] = @encode(_Atomic(int));
172*0a6a1f1dSLionel Sambuc
173*0a6a1f1dSLionel Sambuc// rdar://15824769
174*0a6a1f1dSLionel Sambucid test_id = 0;
175*0a6a1f1dSLionel SambucClass test_class = 0;
176*0a6a1f1dSLionel Sambucconst char g13[] = @encode(__typeof__(*test_class));
177*0a6a1f1dSLionel Sambucconst char g14[] = @encode(__typeof__(*test_id));
178*0a6a1f1dSLionel Sambuc// CHECK: constant [14 x i8] c"{objc_class=}\00"
179*0a6a1f1dSLionel Sambuc// CHECK: constant [15 x i8] c"{objc_object=}\00"
180