encode-test.m 3.69 KB
Newer Older
1
// RUN: %clang_cc1 -triple i686-apple-darwin9 -fobjc-runtime=macosx-fragile-10.5 -emit-llvm -o %t %s
Daniel Dunbar's avatar
Daniel Dunbar committed
2
3
// RUN: FileCheck < %t %s
//
4
// CHECK: @OBJC_METH_VAR_TYPE_{{.*}} = private unnamed_addr constant [16 x i8] c"v12@0:4[3[4@]]8\00"
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

@class Int1;

struct Innermost {
  unsigned char a, b;
};

@interface Int1 {
  signed char a, b;
  struct Innermost *innermost;
}
@end

@implementation Int1
@end
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

@interface Base
{
    struct objc_class *isa;
    int full;
    int full2: 32;
    int _refs: 8;
    int field2: 3;
    unsigned f3: 8;
    short cc;
    unsigned g: 16;
    int r2: 8;
    int r3: 8;
    int r4: 2;
    int r5: 8;
    char c;
}
@end

@interface Derived: Base
{
    char d;
    int _field3: 6;
}
@end

@implementation Base
@end

@implementation Derived
@end

52
53
54
55
56
57
58
59
60
61
62
@interface B1 
{
    struct objc_class *isa;
    Int1 *sBase;
    char c;
}
@end

@implementation B1
@end

63
64
65
@interface Test 
{
	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
71
72
@end

@implementation Test
73
-(void) test3: (Test* [3] [4])b {}
74
- (SEL**) meth : (SEL) arg : (SEL*****) arg1 : (SEL*)arg2 : (SEL**) arg3 {}
75
76
@end

77
struct S { int iS; };
78

79
80
81
82
83
84
85
@interface Object
{
 Class isa;
}
@end
typedef Object MyObj;

86
87
88
int main()
{
	const char *en = @encode(Derived);
89
	const char *eb = @encode(B1);
90
91
        const char *es = @encode(const struct S *);
        const char *ec = @encode(const struct S);
92
        const char *ee = @encode(MyObj *const);
93
94
}

Daniel Dunbar's avatar
Daniel Dunbar committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// CHECK: @g0 = constant [15 x i8] c"{Innermost=CC}\00"
const char g0[] = @encode(struct Innermost);

// CHECK: @g1 = constant [38 x i8] c"{Derived=#ib32b8b3b8sb16b8b8b2b8ccb6}\00"
const char g1[] = @encode(Derived);

// CHECK: @g2 = constant [9 x i8] c"{B1=#@c}\00"
const char g2[] = @encode(B1);

// CHECK: @g3 = constant [8 x i8] c"r^{S=i}\00"
const char g3[] = @encode(const struct S *);

// CHECK: @g4 = constant [6 x i8] c"{S=i}\00"
const char g4[] = @encode(const struct S);

// CHECK: @g5 = constant [12 x i8] c"^{Object=#}\00"
const char g5[] = @encode(MyObj * const);
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

////

enum Enum1X { one, two, three, four };

@interface Base1X {
  unsigned a: 2;
  int b: 3;
  enum Enum1X c: 4;
  unsigned d: 5;
} 
@end

@interface Derived1X: Base1X {
  signed e: 5;
  int f: 4;
  enum Enum1X g: 3;
} 
@end

@implementation Base1X @end

@implementation Derived1X @end

// CHECK: @g6 = constant [18 x i8] c"{Base1X=b2b3b4b5}\00"
const char g6[] = @encode(Base1X);

// CHECK: @g7 = constant [27 x i8] c"{Derived1X=b2b3b4b5b5b4b3}\00"
const char g7[] = @encode(Derived1X);
141
142
143
144
145
146

// CHECK: @g8 = constant [7 x i8] c"{s8=D}\00"
struct s8 {
  long double x;
};
const char g8[] = @encode(struct s8);
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

// CHECK: @g9 = constant [11 x i8] c"{S9=i[0i]}\00"
struct S9 {
  int x;
  int flex[];
};
const char g9[] = @encode(struct S9);

struct f
{
  int i;
  struct{} g[4];
  int tt;
};

162
// CHECK: @g10 = constant [14 x i8] c"{f=i[4{?=}]i}\00"
163
const char g10[] = @encode(struct f);
164
165
166
167

// rdar://9622422
// CHECK: @g11 = constant [2 x i8] c"v\00"
const char g11[] = @encode(void);
168
169
170
171

// PR14628
// CHECK: @g12 = constant [3 x i8] c"Ai\00"
const char g12[] = @encode(_Atomic(int));
172
173
174
175
176
177
178
179

// rdar://15824769
id test_id = 0;
Class test_class = 0;
const char g13[] = @encode(__typeof__(*test_class));
const char g14[] = @encode(__typeof__(*test_id));
// CHECK: constant [14 x i8] c"{objc_class=}\00"
// CHECK: constant [15 x i8] c"{objc_object=}\00"
180
181
182

// CHECK: @g15 = constant [2 x i8] c":\00"
const char g15[] = @encode(SEL);
Hans Wennborg's avatar
Hans Wennborg committed
183
184
185
186
187
188
189
190
191
192
193

typedef typeof(sizeof(int)) size_t;
size_t strlen(const char *s);

// CHECK-LABEL: @test_strlen(
// CHECK: %[[i:.*]] = alloca i32
// CHECK: store i32 1, i32* %[[i]]
void test_strlen() {
  const char array[] = @encode(int);
  int i = strlen(array);
}