2 /* { dg-options "-O2" } */
4 typedef __SIZE_TYPE__
size_t;
5 extern void abort (void);
6 extern void exit (int);
7 extern void *malloc (size_t);
8 extern void *calloc (size_t, size_t);
9 extern void *alloca (size_t);
10 extern void *memcpy (void *, const void *, size_t);
11 extern void *memset (void *, int, size_t);
12 extern char *strcpy (char *, const char *);
23 extern struct A zerol
[0];
26 __attribute__ ((noinline
))
27 test1 (void *q
, int x
)
30 void *p
= &a
.a
[3], *r
;
36 if (__builtin_object_size (p
, 2)
37 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 3)
39 if (__builtin_object_size (&a
.c
[9], 2)
40 != sizeof (a
) - __builtin_offsetof (struct A
, c
) - 9)
42 if (__builtin_object_size (q
, 2) != 0)
44 if (__builtin_object_size (r
, 2)
45 != sizeof (a
) - __builtin_offsetof (struct A
, c
) - 1)
51 if (__builtin_object_size (&y
, 2)
54 if (__builtin_object_size (w
, 2)
57 if (__builtin_object_size (&y
.b
, 2)
58 != sizeof (a
) - __builtin_offsetof (struct A
, b
))
60 if (__builtin_object_size (r
, 2)
61 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 6)
67 if (__builtin_object_size (r
, 2) != 30)
73 if (__builtin_object_size (r
, 2) != 2 * 14)
76 r
= malloc (sizeof (a
));
79 if (__builtin_object_size (r
, 2)
80 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 3)
82 r
= memcpy (r
, "a", 2);
83 if (__builtin_object_size (r
, 2)
84 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 3)
86 r
= memcpy (r
+ 2, "b", 2) + 2;
87 if (__builtin_object_size (r
, 2)
88 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 3 - 4)
91 r
= memset (r
, 'a', 2);
92 if (__builtin_object_size (r
, 2)
93 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 4)
95 r
= memset (r
+ 2, 'b', 2) + 2;
96 if (__builtin_object_size (r
, 2)
97 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 8)
100 r
= strcpy (r
, "ab");
101 if (__builtin_object_size (r
, 2)
102 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 1)
104 r
= strcpy (r
+ 2, "cd") + 2;
105 if (__builtin_object_size (r
, 2)
106 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 5)
108 if (__builtin_object_size (exta
, 2) != 0)
110 if (__builtin_object_size (exta
+ 10, 2) != 0)
112 if (__builtin_object_size (&exta
[5], 2) != 0)
114 if (__builtin_object_size (extb
, 2) != sizeof (extb
))
116 if (__builtin_object_size (extb
+ 10, 2) != sizeof (extb
) - 10)
118 if (__builtin_object_size (&extb
[5], 2) != sizeof (extb
) - 5)
120 if (__builtin_object_size (var
, 2) != 0)
122 if (__builtin_object_size (var
+ 10, 2) != 0)
124 if (__builtin_object_size (&var
[5], 2) != 0)
126 if (__builtin_object_size (zerol
, 2) != 0)
128 if (__builtin_object_size (&zerol
, 2) != 0)
130 if (__builtin_object_size (&zerol
[0], 2) != 0)
132 if (__builtin_object_size (zerol
[0].a
, 2) != 0)
134 if (__builtin_object_size (&zerol
[0].a
[0], 2) != 0)
136 if (__builtin_object_size (&zerol
[0].b
, 2) != 0)
138 if (__builtin_object_size ("abcdefg", 2) != sizeof ("abcdefg"))
140 if (__builtin_object_size ("abcd\0efg", 2) != sizeof ("abcd\0efg"))
142 if (__builtin_object_size (&"abcd\0efg", 2) != sizeof ("abcd\0efg"))
144 if (__builtin_object_size (&"abcd\0efg"[0], 2) != sizeof ("abcd\0efg"))
146 if (__builtin_object_size (&"abcd\0efg"[4], 2) != sizeof ("abcd\0efg") - 4)
148 if (__builtin_object_size ("abcd\0efg" + 5, 2) != sizeof ("abcd\0efg") - 5)
150 if (__builtin_object_size (L
"abcdefg", 2) != sizeof (L
"abcdefg"))
152 r
= (char *) L
"abcd\0efg";
153 if (__builtin_object_size (r
+ 2, 2) != sizeof (L
"abcd\0efg") - 2)
160 __attribute__ ((noinline
))
163 struct B
{ char buf1
[10]; char buf2
[10]; } a
;
167 if (sizeof (a
) != 20)
171 for (i
= 0; i
< 4; ++i
)
177 else if (i
== l1
+ 1)
179 else if (i
== l1
+ 2)
182 if (__builtin_object_size (r
, 2) != 3)
185 for (i
= 0; i
< 4; ++i
)
191 else if (i
== l1
+ 1)
193 else if (i
== l1
+ 2)
196 if (__builtin_object_size (r
, 2) != 0)
199 for (i
= 0; i
< 4; ++i
)
205 else if (i
== l1
+ 1)
207 else if (i
== l1
+ 2)
210 if (__builtin_object_size (r
, 2) != 15)
213 if (__builtin_object_size (r
, 2) != 7)
215 if (__builtin_object_size (r
+ 6, 2) != 1)
218 for (i
= 0; i
< 4; ++i
)
224 else if (i
== l1
+ 1)
226 else if (i
== l1
+ 2)
229 if (__builtin_object_size (r
+ 12, 2) != 0)
234 __attribute__ ((noinline
))
238 struct B
{ struct A a
[2]; struct A b
; char c
[4]; char d
; double e
;
239 _Complex
double f
; } x
;
244 if (__builtin_object_size (buf4
, 2) != sizeof (buf4
))
246 if (__builtin_object_size (&buf4
, 2) != sizeof (buf4
))
248 if (__builtin_object_size (&buf4
[0], 2) != sizeof (buf4
))
250 if (__builtin_object_size (&buf4
[1], 2) != sizeof (buf4
) - 1)
252 if (__builtin_object_size (&x
, 2) != sizeof (x
))
254 if (__builtin_object_size (&x
.a
, 2) != sizeof (x
))
256 if (__builtin_object_size (&x
.a
[0], 2) != sizeof (x
))
258 if (__builtin_object_size (&x
.a
[0].a
, 2) != sizeof (x
))
260 if (__builtin_object_size (&x
.a
[0].a
[0], 2) != sizeof (x
))
262 if (__builtin_object_size (&x
.a
[0].a
[3], 2) != sizeof (x
) - 3)
264 if (__builtin_object_size (&x
.a
[0].b
, 2)
265 != sizeof (x
) - __builtin_offsetof (struct A
, b
))
267 if (__builtin_object_size (&x
.a
[1].c
, 2)
268 != sizeof (x
) - sizeof (struct A
) - __builtin_offsetof (struct A
, c
))
270 if (__builtin_object_size (&x
.a
[1].c
[0], 2)
271 != sizeof (x
) - sizeof (struct A
) - __builtin_offsetof (struct A
, c
))
273 if (__builtin_object_size (&x
.a
[1].c
[3], 2)
274 != sizeof (x
) - sizeof (struct A
) - __builtin_offsetof (struct A
, c
) - 3)
276 if (__builtin_object_size (&x
.b
, 2)
277 != sizeof (x
) - __builtin_offsetof (struct B
, b
))
279 if (__builtin_object_size (&x
.b
.a
, 2)
280 != sizeof (x
) - __builtin_offsetof (struct B
, b
))
282 if (__builtin_object_size (&x
.b
.a
[0], 2)
283 != sizeof (x
) - __builtin_offsetof (struct B
, b
))
285 if (__builtin_object_size (&x
.b
.a
[3], 2)
286 != sizeof (x
) - __builtin_offsetof (struct B
, b
) - 3)
288 if (__builtin_object_size (&x
.b
.b
, 2)
289 != sizeof (x
) - __builtin_offsetof (struct B
, b
)
290 - __builtin_offsetof (struct A
, b
))
292 if (__builtin_object_size (&x
.b
.c
, 2)
293 != sizeof (x
) - __builtin_offsetof (struct B
, b
)
294 - __builtin_offsetof (struct A
, c
))
296 if (__builtin_object_size (&x
.b
.c
[0], 2)
297 != sizeof (x
) - __builtin_offsetof (struct B
, b
)
298 - __builtin_offsetof (struct A
, c
))
300 if (__builtin_object_size (&x
.b
.c
[3], 2)
301 != sizeof (x
) - __builtin_offsetof (struct B
, b
)
302 - __builtin_offsetof (struct A
, c
) - 3)
304 if (__builtin_object_size (&x
.c
, 2)
305 != sizeof (x
) - __builtin_offsetof (struct B
, c
))
307 if (__builtin_object_size (&x
.c
[0], 2)
308 != sizeof (x
) - __builtin_offsetof (struct B
, c
))
310 if (__builtin_object_size (&x
.c
[1], 2)
311 != sizeof (x
) - __builtin_offsetof (struct B
, c
) - 1)
313 if (__builtin_object_size (&x
.d
, 2)
314 != sizeof (x
) - __builtin_offsetof (struct B
, d
))
316 if (__builtin_object_size (&x
.e
, 2)
317 != sizeof (x
) - __builtin_offsetof (struct B
, e
))
319 if (__builtin_object_size (&x
.f
, 2)
320 != sizeof (x
) - __builtin_offsetof (struct B
, f
))
323 if (__builtin_object_size (dp
, 2)
324 != sizeof (x
) - __builtin_offsetof (struct B
, f
))
327 if (__builtin_object_size (dp
, 2)
328 != sizeof (x
) - __builtin_offsetof (struct B
, f
)
332 if (__builtin_object_size (dp
, 2) != sizeof (y
))
334 if (__builtin_object_size (&z
, 2) != sizeof (z
))
337 if (__builtin_object_size (dp
, 2) != sizeof (z
))
340 if (__builtin_object_size (dp
, 2) != sizeof (z
) / 2)
344 struct S
{ unsigned int a
; };
347 __attribute__ ((noinline
))
348 test4 (char *x
, int y
)
353 for (i
= 0; i
< y
; i
++)
357 if (__builtin_object_size (p
, 2) != 0)
364 __attribute__ ((noinline
))
371 for (i
= 0; i
< x
; ++i
)
373 if (__builtin_object_size (p
, 2) != 0)
375 memset (p
, ' ', sizeof (buf
) - 8 - 4 * 4);
379 __attribute__ ((noinline
))
382 struct T
{ char buf
[64]; char buf2
[64]; } t
;
386 for (i
= 0; i
< x
; ++i
)
388 if (__builtin_object_size (p
, 2) != 0)
390 memset (p
, ' ', sizeof (t
) - 8 - 4 * 4);
394 __attribute__ ((noinline
))
398 struct T
{ char buf
[64]; char buf2
[64]; } t
;
399 char *p
= &buf
[64], *q
= &t
.buf
[64];
401 if (__builtin_object_size (p
+ 64, 2) != 0)
403 if (__builtin_object_size (q
+ 63, 2) != sizeof (t
) - 64 - 63)
405 if (__builtin_object_size (q
+ 64, 2) != sizeof (t
) - 64 - 64)
407 if (__builtin_object_size (q
+ 256, 2) != 0)
412 __attribute__ ((noinline
))
415 struct T
{ char buf
[10]; char buf2
[10]; } t
;
416 char *p
= &t
.buf2
[-4];
417 char *q
= &t
.buf2
[0];
418 if (__builtin_object_size (p
, 2) != sizeof (t
) - 10 + 4)
420 if (__builtin_object_size (q
, 2) != sizeof (t
) - 10)
422 /* GCC only handles additions, not subtractions. */
424 if (__builtin_object_size (q
, 2) != 0
425 && __builtin_object_size (q
, 2) != sizeof (t
) - 10 + 8)
428 if (__builtin_object_size (p
, 2) != 0)
436 __asm ("" : "=r" (l1
) : "0" (l1
));
440 test4 ((char *) s
, 10);