1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -O0 %s -o - 2>&1 | FileCheck %s
typedef unsigned long size_t;
struct Foo {
int t[10];
};
#define PS(N) __attribute__((pass_object_size(N)))
int gi = 0;
// CHECK-LABEL: define i32 @ObjectSize0(i8* %{{.*}}, i64)
int ObjectSize0(void *const p PS(0)) {
// CHECK-NOT: @llvm.objectsize
return __builtin_object_size(p, 0);
}
// CHECK-LABEL: define i32 @ObjectSize1(i8* %{{.*}}, i64)
int ObjectSize1(void *const p PS(1)) {
// CHECK-NOT: @llvm.objectsize
return __builtin_object_size(p, 1);
}
// CHECK-LABEL: define i32 @ObjectSize2(i8* %{{.*}}, i64)
int ObjectSize2(void *const p PS(2)) {
// CHECK-NOT: @llvm.objectsize
return __builtin_object_size(p, 2);
}
// CHECK-LABEL: define i32 @ObjectSize3(i8* %{{.*}}, i64)
int ObjectSize3(void *const p PS(3)) {
// CHECK-NOT: @llvm.objectsize
return __builtin_object_size(p, 3);
}
// CHECK-LABEL: define void @test1
void test1() {
struct Foo t[10];
// CHECK: call i32 @ObjectSize0(i8* %{{.*}}, i64 360)
gi = ObjectSize0(&t[1]);
// CHECK: call i32 @ObjectSize1(i8* %{{.*}}, i64 360)
gi = ObjectSize1(&t[1]);
// CHECK: call i32 @ObjectSize2(i8* %{{.*}}, i64 360)
gi = ObjectSize2(&t[1]);
// CHECK: call i32 @ObjectSize3(i8* %{{.*}}, i64 360)
gi = ObjectSize3(&t[1]);
// CHECK: call i32 @ObjectSize0(i8* %{{.*}}, i64 356)
gi = ObjectSize0(&t[1].t[1]);
// CHECK: call i32 @ObjectSize1(i8* %{{.*}}, i64 36)
gi = ObjectSize1(&t[1].t[1]);
// CHECK: call i32 @ObjectSize2(i8* %{{.*}}, i64 356)
gi = ObjectSize2(&t[1].t[1]);
// CHECK: call i32 @ObjectSize3(i8* %{{.*}}, i64 36)
gi = ObjectSize3(&t[1].t[1]);
}
// CHECK-LABEL: define void @test2
void test2(struct Foo *t) {
// CHECK: call i32 @ObjectSize1(i8* %{{.*}}, i64 36)
gi = ObjectSize1(&t->t[1]);
// CHECK: call i32 @ObjectSize3(i8* %{{.*}}, i64 36)
gi = ObjectSize3(&t->t[1]);
}
// CHECK-LABEL: define i32 @_Z27NoViableOverloadObjectSize0Pv
int NoViableOverloadObjectSize0(void *const p) __attribute__((overloadable)) {
// CHECK: @llvm.objectsize
return __builtin_object_size(p, 0);
}
// CHECK-LABEL: define i32 @_Z27NoViableOverloadObjectSize1Pv
int NoViableOverloadObjectSize1(void *const p) __attribute__((overloadable)) {
// CHECK: @llvm.objectsize
return __builtin_object_size(p, 1);
}
// CHECK-LABEL: define i32 @_Z27NoViableOverloadObjectSize2Pv
int NoViableOverloadObjectSize2(void *const p) __attribute__((overloadable)) {
// CHECK: @llvm.objectsize
return __builtin_object_size(p, 2);
}
// CHECK-LABEL: define i32 @_Z27NoViableOverloadObjectSize3Pv
int NoViableOverloadObjectSize3(void *const p) __attribute__((overloadable)) {
// CHECK-NOT: @llvm.objectsize
return __builtin_object_size(p, 3);
}
// CHECK-LABEL: define i32 @_Z27NoViableOverloadObjectSize0Pv
// CHECK-NOT: @llvm.objectsize
int NoViableOverloadObjectSize0(void *const p PS(0))
__attribute__((overloadable)) {
return __builtin_object_size(p, 0);
}
int NoViableOverloadObjectSize1(void *const p PS(1))
__attribute__((overloadable)) {
return __builtin_object_size(p, 1);
}
int NoViableOverloadObjectSize2(void *const p PS(2))
__attribute__((overloadable)) {
return __builtin_object_size(p, 2);
}
int NoViableOverloadObjectSize3(void *const p PS(3))
__attribute__((overloadable)) {
return __builtin_object_size(p, 3);
}
const static int SHOULDNT_BE_CALLED = -100;
int NoViableOverloadObjectSize0(void *const p PS(0))
__attribute__((overloadable, enable_if(p == 0, "never selected"))) {
return SHOULDNT_BE_CALLED;
}
int NoViableOverloadObjectSize1(void *const p PS(1))
__attribute__((overloadable, enable_if(p == 0, "never selected"))) {
return SHOULDNT_BE_CALLED;
}
int NoViableOverloadObjectSize2(void *const p PS(2))
__attribute__((overloadable, enable_if(p == 0, "never selected"))) {
return SHOULDNT_BE_CALLED;
}
int NoViableOverloadObjectSize3(void *const p PS(3))
__attribute__((overloadable, enable_if(p == 0, "never selected"))) {
return SHOULDNT_BE_CALLED;
}
// CHECK-LABEL: define void @test3
void test3() {
struct Foo t[10];
// CHECK: call i32 @_Z27NoViableOverloadObjectSize0PvU17pass_object_size0(i8* %{{.*}}, i64 360)
gi = NoViableOverloadObjectSize0(&t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize1PvU17pass_object_size1(i8* %{{.*}}, i64 360)
gi = NoViableOverloadObjectSize1(&t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize2PvU17pass_object_size2(i8* %{{.*}}, i64 360)
gi = NoViableOverloadObjectSize2(&t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize3PvU17pass_object_size3(i8* %{{.*}}, i64 360)
gi = NoViableOverloadObjectSize3(&t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize0PvU17pass_object_size0(i8* %{{.*}}, i64 356)
gi = NoViableOverloadObjectSize0(&t[1].t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize1PvU17pass_object_size1(i8* %{{.*}}, i64 36)
gi = NoViableOverloadObjectSize1(&t[1].t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize2PvU17pass_object_size2(i8* %{{.*}}, i64 356)
gi = NoViableOverloadObjectSize2(&t[1].t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize3PvU17pass_object_size3(i8* %{{.*}}, i64 36)
gi = NoViableOverloadObjectSize3(&t[1].t[1]);
}
// CHECK-LABEL: define void @test4
void test4(struct Foo *t) {
// CHECK: call i32 @_Z27NoViableOverloadObjectSize0PvU17pass_object_size0(i8* %{{.*}}, i64 %{{.*}})
gi = NoViableOverloadObjectSize0(&t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize1PvU17pass_object_size1(i8* %{{.*}}, i64 %{{.*}})
gi = NoViableOverloadObjectSize1(&t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize2PvU17pass_object_size2(i8* %{{.*}}, i64 %{{.*}})
gi = NoViableOverloadObjectSize2(&t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize3PvU17pass_object_size3(i8* %{{.*}}, i64 0)
gi = NoViableOverloadObjectSize3(&t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize0PvU17pass_object_size0(i8* %{{.*}}, i64 %{{.*}})
gi = NoViableOverloadObjectSize0(&t[1].t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize1PvU17pass_object_size1(i8* %{{.*}}, i64 36)
gi = NoViableOverloadObjectSize1(&t[1].t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize2PvU17pass_object_size2(i8* %{{.*}}, i64 %{{.*}})
gi = NoViableOverloadObjectSize2(&t[1].t[1]);
// CHECK: call i32 @_Z27NoViableOverloadObjectSize3PvU17pass_object_size3(i8* %{{.*}}, i64 36)
gi = NoViableOverloadObjectSize3(&t[1].t[1]);
}
void test5() {
struct Foo t[10];
int (*f)(void *) = &NoViableOverloadObjectSize0;
gi = f(&t[1]);
}
// CHECK-LABEL: define i32 @IndirectObjectSize0
int IndirectObjectSize0(void *const p PS(0)) {
// CHECK: call i32 @ObjectSize0(i8* %{{.*}}, i64 %{{.*}})
// CHECK-NOT: @llvm.objectsize
return ObjectSize0(p);
}
// CHECK-LABEL: define i32 @IndirectObjectSize1
int IndirectObjectSize1(void *const p PS(1)) {
// CHECK: call i32 @ObjectSize1(i8* %{{.*}}, i64 %{{.*}})
// CHECK-NOT: @llvm.objectsize
return ObjectSize1(p);
}
// CHECK-LABEL: define i32 @IndirectObjectSize2
int IndirectObjectSize2(void *const p PS(2)) {
// CHECK: call i32 @ObjectSize2(i8* %{{.*}}, i64 %{{.*}})
// CHECK-NOT: @llvm.objectsize
return ObjectSize2(p);
}
// CHECK-LABEL: define i32 @IndirectObjectSize3
int IndirectObjectSize3(void *const p PS(3)) {
// CHECK: call i32 @ObjectSize3(i8* %{{.*}}, i64 %{{.*}})
// CHECK-NOT: @llvm.objectsize
return ObjectSize3(p);
}
int Overload0(void *, size_t, void *, size_t);
int OverloadNoSize(void *, void *);
int OverloadedObjectSize(void *const p PS(0),
void *const c PS(0))
__attribute__((overloadable)) __asm__("Overload0");
int OverloadedObjectSize(void *const p, void *const c)
__attribute__((overloadable)) __asm__("OverloadNoSize");
// CHECK-LABEL: define void @test6
void test6() {
int known[10], *opaque;
// CHECK: call i32 @"\01Overload0"
gi = OverloadedObjectSize(&known[0], &known[0]);
// CHECK: call i32 @"\01Overload0"
gi = OverloadedObjectSize(&known[0], opaque);
// CHECK: call i32 @"\01Overload0"
gi = OverloadedObjectSize(opaque, &known[0]);
// CHECK: call i32 @"\01Overload0"
gi = OverloadedObjectSize(opaque, opaque);
}
int Identity(void *p, size_t i) { return i; }
// CHECK-NOT: define void @AsmObjectSize
int AsmObjectSize0(void *const p PS(0)) __asm__("Identity");
int AsmObjectSize1(void *const p PS(1)) __asm__("Identity");
int AsmObjectSize2(void *const p PS(2)) __asm__("Identity");
int AsmObjectSize3(void *const p PS(3)) __asm__("Identity");
// CHECK-LABEL: define void @test7
void test7() {
struct Foo t[10];
// CHECK: call i32 @"\01Identity"(i8* %{{.*}}, i64 360)
gi = AsmObjectSize0(&t[1]);
// CHECK: call i32 @"\01Identity"(i8* %{{.*}}, i64 360)
gi = AsmObjectSize1(&t[1]);
// CHECK: call i32 @"\01Identity"(i8* %{{.*}}, i64 360)
gi = AsmObjectSize2(&t[1]);
// CHECK: call i32 @"\01Identity"(i8* %{{.*}}, i64 360)
gi = AsmObjectSize3(&t[1]);
// CHECK: call i32 @"\01Identity"(i8* %{{.*}}, i64 356)
gi = AsmObjectSize0(&t[1].t[1]);
// CHECK: call i32 @"\01Identity"(i8* %{{.*}}, i64 36)
gi = AsmObjectSize1(&t[1].t[1]);
// CHECK: call i32 @"\01Identity"(i8* %{{.*}}, i64 356)
gi = AsmObjectSize2(&t[1].t[1]);
// CHECK: call i32 @"\01Identity"(i8* %{{.*}}, i64 36)
gi = AsmObjectSize3(&t[1].t[1]);
}
// CHECK-LABEL: define void @test8
void test8(struct Foo *t) {
// CHECK: call i32 @"\01Identity"(i8* %{{.*}}, i64 36)
gi = AsmObjectSize1(&t[1].t[1]);
// CHECK: call i32 @"\01Identity"(i8* %{{.*}}, i64 36)
gi = AsmObjectSize3(&t[1].t[1]);
}
void DifferingObjectSize0(void *const p __attribute__((pass_object_size(0))));
void DifferingObjectSize1(void *const p __attribute__((pass_object_size(1))));
void DifferingObjectSize2(void *const p __attribute__((pass_object_size(2))));
void DifferingObjectSize3(void *const p __attribute__((pass_object_size(3))));
// CHECK-LABEL: define void @test9
void test9(void *const p __attribute__((pass_object_size(0)))) {
// CHECK: @llvm.objectsize
DifferingObjectSize2(p);
// CHECK-NOT: @llvm.objectsize
DifferingObjectSize0(p);
DifferingObjectSize1(p);
// CHECK: call void @DifferingObjectSize3(i8* %{{.*}}, i64 0)
DifferingObjectSize3(p);
}
// CHECK-LABEL: define void @test10
void test10(void *const p __attribute__((pass_object_size(1)))) {
// CHECK: @llvm.objectsize
DifferingObjectSize2(p);
// CHECK: @llvm.objectsize
DifferingObjectSize0(p);
// CHECK-NOT: @llvm.objectsize
DifferingObjectSize1(p);
// CHECK: call void @DifferingObjectSize3(i8* %{{.*}}, i64 0)
DifferingObjectSize3(p);
}
// CHECK-LABEL: define void @test11
void test11(void *const p __attribute__((pass_object_size(2)))) {
// CHECK: @llvm.objectsize
DifferingObjectSize0(p);
// CHECK: @llvm.objectsize
DifferingObjectSize1(p);
// CHECK-NOT: @llvm.objectsize
DifferingObjectSize2(p);
// CHECK: call void @DifferingObjectSize3(i8* %{{.*}}, i64 0)
DifferingObjectSize3(p);
}
// CHECK-LABEL: define void @test12
void test12(void *const p __attribute__((pass_object_size(3)))) {
// CHECK: @llvm.objectsize
DifferingObjectSize0(p);
// CHECK: @llvm.objectsize
DifferingObjectSize1(p);
// CHECK-NOT: @llvm.objectsize
DifferingObjectSize2(p);
DifferingObjectSize3(p);
}
// CHECK-LABEL: define void @test13
void test13() {
// Ensuring that we don't lower objectsize if the expression has side-effects
char c[10];
char *p = c;
// CHECK: @llvm.objectsize
ObjectSize0(p);
// CHECK-NOT: @llvm.objectsize
ObjectSize0(++p);
ObjectSize0(p++);
}
|