Debian Codegraph @

clang/test/CodeGenObjC/encode-test.m

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