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 extc
[];
28 __attribute__ ((noinline
))
29 test1 (void *q
, int x
)
32 void *p
= &a
.a
[3], *r
;
34 struct A vara
[x
+ 10];
39 if (__builtin_object_size (p
, 3) != sizeof (a
.a
) - 3)
41 if (__builtin_object_size (&a
.c
[9], 3)
44 if (__builtin_object_size (q
, 3) != 0)
46 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 9)
52 if (__builtin_object_size (&y
, 3) != sizeof (y
))
54 if (__builtin_object_size (w
, 3) != sizeof (w
))
56 if (__builtin_object_size (&y
.b
, 3) != sizeof (a
.b
))
58 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 6)
64 if (__builtin_object_size (r
, 3) != 30)
70 if (__builtin_object_size (r
, 3) != 2 * 14)
73 r
= malloc (sizeof (a
));
76 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 3)
78 r
= memcpy (r
, "a", 2);
79 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 3)
81 r
= memcpy (r
+ 2, "b", 2) + 2;
82 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 3 - 4)
85 r
= memset (r
, 'a', 2);
86 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 4)
88 r
= memset (r
+ 2, 'b', 2) + 2;
89 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 8)
93 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 1)
95 r
= strcpy (r
+ 2, "cd") + 2;
96 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 5)
98 if (__builtin_object_size (exta
, 3) != 0)
100 if (__builtin_object_size (exta
+ 10, 3) != 0)
102 if (__builtin_object_size (&exta
[5], 3) != 0)
104 if (__builtin_object_size (extb
, 3) != sizeof (extb
))
106 if (__builtin_object_size (extb
+ 10, 3) != sizeof (extb
) - 10)
108 if (__builtin_object_size (&extb
[5], 3) != sizeof (extb
) - 5)
110 if (__builtin_object_size (extc
, 3) != 0)
112 if (__builtin_object_size (extc
+ 10, 3) != 0)
114 if (__builtin_object_size (&extc
[5], 3) != 0)
116 if (__builtin_object_size (&extc
->a
, 3) != 0)
118 if (__builtin_object_size (&(extc
+ 10)->b
, 3) != 0)
120 if (__builtin_object_size (&extc
[5].c
[3], 3) != 0)
122 if (__builtin_object_size (var
, 3) != 0)
124 if (__builtin_object_size (var
+ 10, 3) != 0)
126 if (__builtin_object_size (&var
[5], 3) != 0)
128 if (__builtin_object_size (vara
, 3) != 0)
130 if (__builtin_object_size (vara
+ 10, 3) != 0)
132 if (__builtin_object_size (&vara
[5], 3) != 0)
134 if (__builtin_object_size (&vara
[0].a
, 3) != sizeof (vara
[0].a
))
136 if (__builtin_object_size (&vara
[10].a
[0], 3) != sizeof (vara
[0].a
))
138 if (__builtin_object_size (&vara
[5].a
[4], 3) != sizeof (vara
[0].a
) - 4)
140 if (__builtin_object_size (&vara
[5].b
, 3) != sizeof (vara
[0].b
))
142 if (__builtin_object_size (&vara
[7].c
[7], 3) != sizeof (vara
[0].c
) - 7)
144 if (__builtin_object_size (zerol
, 3) != 0)
146 if (__builtin_object_size (&zerol
, 3) != 0)
148 if (__builtin_object_size (&zerol
[0], 3) != 0)
150 if (__builtin_object_size (zerol
[0].a
, 3) != 0)
152 if (__builtin_object_size (&zerol
[0].a
[0], 3) != 0)
154 if (__builtin_object_size (&zerol
[0].b
, 3) != 0)
156 if (__builtin_object_size ("abcdefg", 3) != sizeof ("abcdefg"))
158 if (__builtin_object_size ("abcd\0efg", 3) != sizeof ("abcd\0efg"))
160 if (__builtin_object_size (&"abcd\0efg", 3) != sizeof ("abcd\0efg"))
162 if (__builtin_object_size (&"abcd\0efg"[0], 3) != sizeof ("abcd\0efg"))
164 if (__builtin_object_size (&"abcd\0efg"[4], 3) != sizeof ("abcd\0efg") - 4)
166 if (__builtin_object_size ("abcd\0efg" + 5, 3) != sizeof ("abcd\0efg") - 5)
168 if (__builtin_object_size (L
"abcdefg", 3) != sizeof (L
"abcdefg"))
170 r
= (char *) L
"abcd\0efg";
171 if (__builtin_object_size (r
+ 2, 3) != sizeof (L
"abcd\0efg") - 2)
178 __attribute__ ((noinline
))
181 struct B
{ char buf1
[10]; char buf2
[10]; } a
;
185 if (sizeof (a
) != 20)
189 for (i
= 0; i
< 4; ++i
)
195 else if (i
== l1
+ 1)
197 else if (i
== l1
+ 2)
200 if (__builtin_object_size (r
, 3) != sizeof (a
.buf1
) - 9)
203 for (i
= 0; i
< 4; ++i
)
209 else if (i
== l1
+ 1)
211 else if (i
== l1
+ 2)
214 if (__builtin_object_size (r
, 3) != 0)
217 for (i
= 0; i
< 4; ++i
)
223 else if (i
== l1
+ 1)
225 else if (i
== l1
+ 2)
228 if (__builtin_object_size (r
, 3) != sizeof (a
.buf1
) - 6)
231 if (__builtin_object_size (r
, 3) != sizeof (a
.buf1
) - 6 - 2)
233 if (__builtin_object_size (r
+ 1, 3) != sizeof (a
.buf1
) - 6 - 3)
238 __attribute__ ((noinline
))
242 struct B
{ struct A a
[2]; struct A b
; char c
[4]; char d
; double e
;
243 _Complex
double f
; } x
;
248 if (__builtin_object_size (buf4
, 3) != sizeof (buf4
))
250 if (__builtin_object_size (&buf4
, 3) != sizeof (buf4
))
252 if (__builtin_object_size (&buf4
[0], 3) != sizeof (buf4
))
254 if (__builtin_object_size (&buf4
[1], 3) != sizeof (buf4
) - 1)
256 if (__builtin_object_size (&x
, 3) != sizeof (x
))
258 if (__builtin_object_size (&x
.a
, 3) != sizeof (x
.a
))
260 if (__builtin_object_size (&x
.a
[0], 3) != sizeof (x
.a
))
262 if (__builtin_object_size (&x
.a
[0].a
, 3) != sizeof (x
.a
[0].a
))
264 if (__builtin_object_size (&x
.a
[0].a
[0], 3) != sizeof (x
.a
[0].a
))
266 if (__builtin_object_size (&x
.a
[0].a
[3], 3) != sizeof (x
.a
[0].a
) - 3)
268 if (__builtin_object_size (&x
.a
[0].b
, 3) != sizeof (x
.a
[0].b
))
270 if (__builtin_object_size (&x
.a
[1].c
, 3) != sizeof (x
.a
[1].c
))
272 if (__builtin_object_size (&x
.a
[1].c
[0], 3) != sizeof (x
.a
[1].c
))
274 if (__builtin_object_size (&x
.a
[1].c
[3], 3) != sizeof (x
.a
[1].c
) - 3)
276 if (__builtin_object_size (&x
.b
, 3) != sizeof (x
.b
))
278 if (__builtin_object_size (&x
.b
.a
, 3) != sizeof (x
.b
.a
))
280 if (__builtin_object_size (&x
.b
.a
[0], 3) != sizeof (x
.b
.a
))
282 if (__builtin_object_size (&x
.b
.a
[3], 3) != sizeof (x
.b
.a
) - 3)
284 if (__builtin_object_size (&x
.b
.b
, 3) != sizeof (x
.b
.b
))
286 if (__builtin_object_size (&x
.b
.c
, 3) != sizeof (x
.b
.c
))
288 if (__builtin_object_size (&x
.b
.c
[0], 3) != sizeof (x
.b
.c
))
290 if (__builtin_object_size (&x
.b
.c
[3], 3) != sizeof (x
.b
.c
) - 3)
292 if (__builtin_object_size (&x
.c
, 3) != sizeof (x
.c
))
294 if (__builtin_object_size (&x
.c
[0], 3) != sizeof (x
.c
))
296 if (__builtin_object_size (&x
.c
[1], 3) != sizeof (x
.c
) - 1)
298 if (__builtin_object_size (&x
.d
, 3) != sizeof (x
.d
))
300 if (__builtin_object_size (&x
.e
, 3) != sizeof (x
.e
))
302 if (__builtin_object_size (&x
.f
, 3) != sizeof (x
.f
))
305 if (__builtin_object_size (dp
, 3) != sizeof (x
.f
) / 2)
308 if (__builtin_object_size (dp
, 3) != sizeof (x
.f
) / 2)
311 if (__builtin_object_size (dp
, 3) != sizeof (y
))
313 if (__builtin_object_size (&z
, 3) != sizeof (z
))
316 if (__builtin_object_size (dp
, 3) != sizeof (z
) / 2)
319 if (__builtin_object_size (dp
, 3) != sizeof (z
) / 2)
323 struct S
{ unsigned int a
; };
326 __attribute__ ((noinline
))
327 test4 (char *x
, int y
)
332 for (i
= 0; i
< y
; i
++)
336 if (__builtin_object_size (p
, 3) != 0)
343 __attribute__ ((noinline
))
346 struct T
{ char buf
[64]; char buf2
[64]; } t
;
350 for (i
= 0; i
< x
; ++i
)
352 if (__builtin_object_size (p
, 3) != 0)
354 memset (p
, ' ', sizeof (t
.buf
) - 8 - 4 * 4);
358 __attribute__ ((noinline
))
362 struct T
{ char buf
[64]; char buf2
[64]; } t
;
363 char *p
= &buf
[64], *q
= &t
.buf
[64];
365 if (__builtin_object_size (p
+ 64, 3) != 0)
367 if (__builtin_object_size (q
+ 0, 3) != 0)
369 if (__builtin_object_size (q
+ 64, 3) != 0)
374 __attribute__ ((noinline
))
377 struct T
{ char buf
[10]; char buf2
[10]; } t
;
378 char *p
= &t
.buf2
[-4];
379 char *q
= &t
.buf2
[0];
380 if (__builtin_object_size (p
, 3) != 0)
382 if (__builtin_object_size (q
, 3) != sizeof (t
.buf2
))
385 if (__builtin_object_size (q
, 3) != 0)
388 if (__builtin_object_size (q
, 3) != 0)
391 if (__builtin_object_size (p
, 3) != 0)
399 __asm ("" : "=r" (l1
) : "0" (l1
));
403 test4 ((char *) s
, 10);