2 /* { dg-options "-O2" } */
3 /* { dg-require-effective-target alloca } */
5 typedef __SIZE_TYPE__
size_t;
6 extern void abort (void);
7 extern void exit (int);
8 extern void *malloc (size_t);
9 extern void *calloc (size_t, size_t);
10 extern void *alloca (size_t);
11 extern void *memcpy (void *, const void *, size_t);
12 extern void *memset (void *, int, size_t);
13 extern char *strcpy (char *, const char *);
24 extern struct A zerol
[0];
27 __attribute__ ((noinline
))
28 test1 (void *q
, int x
)
31 void *p
= &a
.a
[3], *r
;
37 if (__builtin_object_size (p
, 2)
38 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 3)
40 if (__builtin_object_size (&a
.c
[9], 2)
41 != sizeof (a
) - __builtin_offsetof (struct A
, c
) - 9)
43 if (__builtin_object_size (q
, 2) != 0)
45 if (__builtin_object_size (r
, 2)
46 != sizeof (a
) - __builtin_offsetof (struct A
, c
) - 1)
52 if (__builtin_object_size (&y
, 2)
55 if (__builtin_object_size (w
, 2)
58 if (__builtin_object_size (&y
.b
, 2)
59 != sizeof (a
) - __builtin_offsetof (struct A
, b
))
61 if (__builtin_object_size (r
, 2)
62 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 6)
68 if (__builtin_object_size (r
, 2) != 30)
74 if (__builtin_object_size (r
, 2) != 2 * 14)
77 r
= malloc (sizeof (a
));
80 if (__builtin_object_size (r
, 2)
81 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 3)
83 r
= memcpy (r
, "a", 2);
84 if (__builtin_object_size (r
, 2)
85 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 3)
87 r
= memcpy (r
+ 2, "b", 2) + 2;
88 if (__builtin_object_size (r
, 2)
89 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 3 - 4)
92 r
= memset (r
, 'a', 2);
93 if (__builtin_object_size (r
, 2)
94 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 4)
96 r
= memset (r
+ 2, 'b', 2) + 2;
97 if (__builtin_object_size (r
, 2)
98 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 8)
101 r
= strcpy (r
, "ab");
102 if (__builtin_object_size (r
, 2)
103 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 1)
105 r
= strcpy (r
+ 2, "cd") + 2;
106 if (__builtin_object_size (r
, 2)
107 != sizeof (a
) - __builtin_offsetof (struct A
, a
) - 5)
109 if (__builtin_object_size (exta
, 2) != 0)
111 if (__builtin_object_size (exta
+ 10, 2) != 0)
113 if (__builtin_object_size (&exta
[5], 2) != 0)
115 if (__builtin_object_size (extb
, 2) != sizeof (extb
))
117 if (__builtin_object_size (extb
+ 10, 2) != sizeof (extb
) - 10)
119 if (__builtin_object_size (&extb
[5], 2) != sizeof (extb
) - 5)
121 if (__builtin_object_size (var
, 2) != 0)
123 if (__builtin_object_size (var
+ 10, 2) != 0)
125 if (__builtin_object_size (&var
[5], 2) != 0)
127 if (__builtin_object_size (zerol
, 2) != 0)
129 if (__builtin_object_size (&zerol
, 2) != 0)
131 if (__builtin_object_size (&zerol
[0], 2) != 0)
133 if (__builtin_object_size (zerol
[0].a
, 2) != 0)
135 if (__builtin_object_size (&zerol
[0].a
[0], 2) != 0)
137 if (__builtin_object_size (&zerol
[0].b
, 2) != 0)
139 if (__builtin_object_size ("abcdefg", 2) != sizeof ("abcdefg"))
141 if (__builtin_object_size ("abcd\0efg", 2) != sizeof ("abcd\0efg"))
143 if (__builtin_object_size (&"abcd\0efg", 2) != sizeof ("abcd\0efg"))
145 if (__builtin_object_size (&"abcd\0efg"[0], 2) != sizeof ("abcd\0efg"))
147 if (__builtin_object_size (&"abcd\0efg"[4], 2) != sizeof ("abcd\0efg") - 4)
149 if (__builtin_object_size ("abcd\0efg" + 5, 2) != sizeof ("abcd\0efg") - 5)
151 if (__builtin_object_size (L
"abcdefg", 2) != sizeof (L
"abcdefg"))
153 r
= (char *) L
"abcd\0efg";
154 if (__builtin_object_size (r
+ 2, 2) != sizeof (L
"abcd\0efg") - 2)
161 __attribute__ ((noinline
))
164 struct B
{ char buf1
[10]; char buf2
[10]; } a
;
168 if (sizeof (a
) != 20)
172 for (i
= 0; i
< 4; ++i
)
178 else if (i
== l1
+ 1)
180 else if (i
== l1
+ 2)
183 if (__builtin_object_size (r
, 2) != 3)
186 for (i
= 0; i
< 4; ++i
)
192 else if (i
== l1
+ 1)
194 else if (i
== l1
+ 2)
197 if (__builtin_object_size (r
, 2) != 0)
200 for (i
= 0; i
< 4; ++i
)
206 else if (i
== l1
+ 1)
208 else if (i
== l1
+ 2)
211 if (__builtin_object_size (r
, 2) != 15)
214 if (__builtin_object_size (r
, 2) != 7)
216 if (__builtin_object_size (r
+ 6, 2) != 1)
219 for (i
= 0; i
< 4; ++i
)
225 else if (i
== l1
+ 1)
227 else if (i
== l1
+ 2)
230 if (__builtin_object_size (r
+ 12, 2) != 0)
235 __attribute__ ((noinline
))
239 struct B
{ struct A a
[2]; struct A b
; char c
[4]; char d
; double e
;
240 _Complex
double f
; } x
;
245 if (__builtin_object_size (buf4
, 2) != sizeof (buf4
))
247 if (__builtin_object_size (&buf4
, 2) != sizeof (buf4
))
249 if (__builtin_object_size (&buf4
[0], 2) != sizeof (buf4
))
251 if (__builtin_object_size (&buf4
[1], 2) != sizeof (buf4
) - 1)
253 if (__builtin_object_size (&x
, 2) != sizeof (x
))
255 if (__builtin_object_size (&x
.a
, 2) != sizeof (x
))
257 if (__builtin_object_size (&x
.a
[0], 2) != sizeof (x
))
259 if (__builtin_object_size (&x
.a
[0].a
, 2) != sizeof (x
))
261 if (__builtin_object_size (&x
.a
[0].a
[0], 2) != sizeof (x
))
263 if (__builtin_object_size (&x
.a
[0].a
[3], 2) != sizeof (x
) - 3)
265 if (__builtin_object_size (&x
.a
[0].b
, 2)
266 != sizeof (x
) - __builtin_offsetof (struct A
, b
))
268 if (__builtin_object_size (&x
.a
[1].c
, 2)
269 != sizeof (x
) - sizeof (struct A
) - __builtin_offsetof (struct A
, c
))
271 if (__builtin_object_size (&x
.a
[1].c
[0], 2)
272 != sizeof (x
) - sizeof (struct A
) - __builtin_offsetof (struct A
, c
))
274 if (__builtin_object_size (&x
.a
[1].c
[3], 2)
275 != sizeof (x
) - sizeof (struct A
) - __builtin_offsetof (struct A
, c
) - 3)
277 if (__builtin_object_size (&x
.b
, 2)
278 != sizeof (x
) - __builtin_offsetof (struct B
, b
))
280 if (__builtin_object_size (&x
.b
.a
, 2)
281 != sizeof (x
) - __builtin_offsetof (struct B
, b
))
283 if (__builtin_object_size (&x
.b
.a
[0], 2)
284 != sizeof (x
) - __builtin_offsetof (struct B
, b
))
286 if (__builtin_object_size (&x
.b
.a
[3], 2)
287 != sizeof (x
) - __builtin_offsetof (struct B
, b
) - 3)
289 if (__builtin_object_size (&x
.b
.b
, 2)
290 != sizeof (x
) - __builtin_offsetof (struct B
, b
)
291 - __builtin_offsetof (struct A
, b
))
293 if (__builtin_object_size (&x
.b
.c
, 2)
294 != sizeof (x
) - __builtin_offsetof (struct B
, b
)
295 - __builtin_offsetof (struct A
, c
))
297 if (__builtin_object_size (&x
.b
.c
[0], 2)
298 != sizeof (x
) - __builtin_offsetof (struct B
, b
)
299 - __builtin_offsetof (struct A
, c
))
301 if (__builtin_object_size (&x
.b
.c
[3], 2)
302 != sizeof (x
) - __builtin_offsetof (struct B
, b
)
303 - __builtin_offsetof (struct A
, c
) - 3)
305 if (__builtin_object_size (&x
.c
, 2)
306 != sizeof (x
) - __builtin_offsetof (struct B
, c
))
308 if (__builtin_object_size (&x
.c
[0], 2)
309 != sizeof (x
) - __builtin_offsetof (struct B
, c
))
311 if (__builtin_object_size (&x
.c
[1], 2)
312 != sizeof (x
) - __builtin_offsetof (struct B
, c
) - 1)
314 if (__builtin_object_size (&x
.d
, 2)
315 != sizeof (x
) - __builtin_offsetof (struct B
, d
))
317 if (__builtin_object_size (&x
.e
, 2)
318 != sizeof (x
) - __builtin_offsetof (struct B
, e
))
320 if (__builtin_object_size (&x
.f
, 2)
321 != sizeof (x
) - __builtin_offsetof (struct B
, f
))
324 if (__builtin_object_size (dp
, 2)
325 != sizeof (x
) - __builtin_offsetof (struct B
, f
))
328 if (__builtin_object_size (dp
, 2)
329 != sizeof (x
) - __builtin_offsetof (struct B
, f
)
333 if (__builtin_object_size (dp
, 2) != sizeof (y
))
335 if (__builtin_object_size (&z
, 2) != sizeof (z
))
338 if (__builtin_object_size (dp
, 2) != sizeof (z
))
341 if (__builtin_object_size (dp
, 2) != sizeof (z
) / 2)
345 struct S
{ unsigned int a
; };
348 __attribute__ ((noinline
))
349 test4 (char *x
, int y
)
354 for (i
= 0; i
< y
; i
++)
358 if (__builtin_object_size (p
, 2) != 0)
365 __attribute__ ((noinline
))
372 for (i
= 0; i
< x
; ++i
)
374 if (__builtin_object_size (p
, 2) != 0)
376 memset (p
, ' ', sizeof (buf
) - 8 - 4 * 4);
380 __attribute__ ((noinline
))
383 struct T
{ char buf
[64]; char buf2
[64]; } t
;
387 for (i
= 0; i
< x
; ++i
)
389 if (__builtin_object_size (p
, 2) != 0)
391 memset (p
, ' ', sizeof (t
) - 8 - 4 * 4);
395 __attribute__ ((noinline
))
399 struct T
{ char buf
[64]; char buf2
[64]; } t
;
400 char *p
= &buf
[64], *q
= &t
.buf
[64];
402 if (__builtin_object_size (p
+ 64, 2) != 0)
404 if (__builtin_object_size (q
+ 63, 2) != sizeof (t
) - 64 - 63)
406 if (__builtin_object_size (q
+ 64, 2) != sizeof (t
) - 64 - 64)
408 if (__builtin_object_size (q
+ 256, 2) != 0)
413 __attribute__ ((noinline
))
416 struct T
{ char buf
[10]; char buf2
[10]; } t
;
417 char *p
= &t
.buf2
[-4];
418 char *q
= &t
.buf2
[0];
419 if (__builtin_object_size (p
, 2) != sizeof (t
) - 10 + 4)
421 if (__builtin_object_size (q
, 2) != sizeof (t
) - 10)
423 /* GCC only handles additions, not subtractions. */
425 if (__builtin_object_size (q
, 2) != 0
426 && __builtin_object_size (q
, 2) != sizeof (t
) - 10 + 8)
429 if (__builtin_object_size (p
, 2) != 0)
437 __asm ("" : "=r" (l1
) : "0" (l1
));
441 test4 ((char *) s
, 10);