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 extc
[];
27 __attribute__ ((noinline
))
28 test1 (void *q
, int x
)
31 void *p
= &a
.a
[3], *r
;
33 struct A vara
[x
+ 10];
38 if (__builtin_object_size (p
, 3) != sizeof (a
.a
) - 3)
40 if (__builtin_object_size (&a
.c
[9], 3)
43 if (__builtin_object_size (q
, 3) != 0)
45 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 9)
51 if (__builtin_object_size (&y
, 3) != sizeof (y
))
53 if (__builtin_object_size (w
, 3) != sizeof (w
))
55 if (__builtin_object_size (&y
.b
, 3) != sizeof (a
.b
))
57 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 6)
63 if (__builtin_object_size (r
, 3) != 30)
69 if (__builtin_object_size (r
, 3) != 2 * 14)
72 r
= malloc (sizeof (a
));
75 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 3)
77 r
= memcpy (r
, "a", 2);
78 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 3)
80 r
= memcpy (r
+ 2, "b", 2) + 2;
81 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 3 - 4)
84 r
= memset (r
, 'a', 2);
85 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 4)
87 r
= memset (r
+ 2, 'b', 2) + 2;
88 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 8)
92 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 1)
94 r
= strcpy (r
+ 2, "cd") + 2;
95 if (__builtin_object_size (r
, 3) != sizeof (a
.a
) - 5)
97 if (__builtin_object_size (exta
, 3) != 0)
99 if (__builtin_object_size (exta
+ 10, 3) != 0)
101 if (__builtin_object_size (&exta
[5], 3) != 0)
103 if (__builtin_object_size (extb
, 3) != sizeof (extb
))
105 if (__builtin_object_size (extb
+ 10, 3) != sizeof (extb
) - 10)
107 if (__builtin_object_size (&extb
[5], 3) != sizeof (extb
) - 5)
109 if (__builtin_object_size (extc
, 3) != 0)
111 if (__builtin_object_size (extc
+ 10, 3) != 0)
113 if (__builtin_object_size (&extc
[5], 3) != 0)
115 if (__builtin_object_size (&extc
->a
, 3) != 0)
117 if (__builtin_object_size (&(extc
+ 10)->b
, 3) != 0)
119 if (__builtin_object_size (&extc
[5].c
[3], 3) != 0)
121 if (__builtin_object_size (var
, 3) != 0)
123 if (__builtin_object_size (var
+ 10, 3) != 0)
125 if (__builtin_object_size (&var
[5], 3) != 0)
127 if (__builtin_object_size (vara
, 3) != 0)
129 if (__builtin_object_size (vara
+ 10, 3) != 0)
131 if (__builtin_object_size (&vara
[5], 3) != 0)
133 if (__builtin_object_size (&vara
[0].a
, 3) != 0)
135 if (__builtin_object_size (&vara
[10].a
[0], 3) != 0)
137 if (__builtin_object_size (&vara
[5].a
[4], 3) != 0)
139 if (__builtin_object_size (&vara
[5].b
, 3) != 0)
141 if (__builtin_object_size (&vara
[7].c
[7], 3) != 0)
143 if (__builtin_object_size (zerol
, 3) != 0)
145 if (__builtin_object_size (&zerol
, 3) != 0)
147 if (__builtin_object_size (&zerol
[0], 3) != 0)
149 if (__builtin_object_size (zerol
[0].a
, 3) != 0)
151 if (__builtin_object_size (&zerol
[0].a
[0], 3) != 0)
153 if (__builtin_object_size (&zerol
[0].b
, 3) != 0)
155 if (__builtin_object_size ("abcdefg", 3) != sizeof ("abcdefg"))
157 if (__builtin_object_size ("abcd\0efg", 3) != sizeof ("abcd\0efg"))
159 if (__builtin_object_size (&"abcd\0efg", 3) != sizeof ("abcd\0efg"))
161 if (__builtin_object_size (&"abcd\0efg"[0], 3) != sizeof ("abcd\0efg"))
163 if (__builtin_object_size (&"abcd\0efg"[4], 3) != sizeof ("abcd\0efg") - 4)
165 if (__builtin_object_size ("abcd\0efg" + 5, 3) != sizeof ("abcd\0efg") - 5)
167 if (__builtin_object_size (L
"abcdefg", 3) != sizeof (L
"abcdefg"))
169 r
= (char *) L
"abcd\0efg";
170 if (__builtin_object_size (r
+ 2, 3) != sizeof (L
"abcd\0efg") - 2)
177 __attribute__ ((noinline
))
180 struct B
{ char buf1
[10]; char buf2
[10]; } a
;
184 if (sizeof (a
) != 20)
188 for (i
= 0; i
< 4; ++i
)
194 else if (i
== l1
+ 1)
196 else if (i
== l1
+ 2)
199 if (__builtin_object_size (r
, 3) != sizeof (a
.buf1
) - 9)
202 for (i
= 0; i
< 4; ++i
)
208 else if (i
== l1
+ 1)
210 else if (i
== l1
+ 2)
213 if (__builtin_object_size (r
, 3) != 0)
216 for (i
= 0; i
< 4; ++i
)
222 else if (i
== l1
+ 1)
224 else if (i
== l1
+ 2)
227 if (__builtin_object_size (r
, 3) != sizeof (a
.buf1
) - 6)
230 if (__builtin_object_size (r
, 3) != sizeof (a
.buf1
) - 6 - 2)
232 if (__builtin_object_size (r
+ 1, 3) != sizeof (a
.buf1
) - 6 - 3)
237 __attribute__ ((noinline
))
241 struct B
{ struct A a
[2]; struct A b
; char c
[4]; char d
; double e
;
242 _Complex
double f
; } x
;
247 if (__builtin_object_size (buf4
, 3) != sizeof (buf4
))
249 if (__builtin_object_size (&buf4
, 3) != sizeof (buf4
))
251 if (__builtin_object_size (&buf4
[0], 3) != sizeof (buf4
))
253 if (__builtin_object_size (&buf4
[1], 3) != sizeof (buf4
) - 1)
255 if (__builtin_object_size (&x
, 3) != sizeof (x
))
257 if (__builtin_object_size (&x
.a
, 3) != sizeof (x
.a
))
259 if (__builtin_object_size (&x
.a
[0], 3) != sizeof (x
.a
))
261 if (__builtin_object_size (&x
.a
[0].a
, 3) != sizeof (x
.a
[0].a
))
263 if (__builtin_object_size (&x
.a
[0].a
[0], 3) != sizeof (x
.a
[0].a
))
265 if (__builtin_object_size (&x
.a
[0].a
[3], 3) != sizeof (x
.a
[0].a
) - 3)
267 if (__builtin_object_size (&x
.a
[0].b
, 3) != sizeof (x
.a
[0].b
))
269 if (__builtin_object_size (&x
.a
[1].c
, 3) != sizeof (x
.a
[1].c
))
271 if (__builtin_object_size (&x
.a
[1].c
[0], 3) != sizeof (x
.a
[1].c
))
273 if (__builtin_object_size (&x
.a
[1].c
[3], 3) != sizeof (x
.a
[1].c
) - 3)
275 if (__builtin_object_size (&x
.b
, 3) != sizeof (x
.b
))
277 if (__builtin_object_size (&x
.b
.a
, 3) != sizeof (x
.b
.a
))
279 if (__builtin_object_size (&x
.b
.a
[0], 3) != sizeof (x
.b
.a
))
281 if (__builtin_object_size (&x
.b
.a
[3], 3) != sizeof (x
.b
.a
) - 3)
283 if (__builtin_object_size (&x
.b
.b
, 3) != sizeof (x
.b
.b
))
285 if (__builtin_object_size (&x
.b
.c
, 3) != sizeof (x
.b
.c
))
287 if (__builtin_object_size (&x
.b
.c
[0], 3) != sizeof (x
.b
.c
))
289 if (__builtin_object_size (&x
.b
.c
[3], 3) != sizeof (x
.b
.c
) - 3)
291 if (__builtin_object_size (&x
.c
, 3) != sizeof (x
.c
))
293 if (__builtin_object_size (&x
.c
[0], 3) != sizeof (x
.c
))
295 if (__builtin_object_size (&x
.c
[1], 3) != sizeof (x
.c
) - 1)
297 if (__builtin_object_size (&x
.d
, 3) != sizeof (x
.d
))
299 if (__builtin_object_size (&x
.e
, 3) != sizeof (x
.e
))
301 if (__builtin_object_size (&x
.f
, 3) != sizeof (x
.f
))
304 if (__builtin_object_size (dp
, 3) != sizeof (x
.f
) / 2)
307 if (__builtin_object_size (dp
, 3) != sizeof (x
.f
) / 2)
310 if (__builtin_object_size (dp
, 3) != sizeof (y
))
312 if (__builtin_object_size (&z
, 3) != sizeof (z
))
315 if (__builtin_object_size (dp
, 3) != sizeof (z
) / 2)
318 if (__builtin_object_size (dp
, 3) != sizeof (z
) / 2)
322 struct S
{ unsigned int a
; };
325 __attribute__ ((noinline
))
326 test4 (char *x
, int y
)
331 for (i
= 0; i
< y
; i
++)
335 if (__builtin_object_size (p
, 3) != 0)
342 __attribute__ ((noinline
))
345 struct T
{ char buf
[64]; char buf2
[64]; } t
;
349 for (i
= 0; i
< x
; ++i
)
351 if (__builtin_object_size (p
, 3) != 0)
353 memset (p
, ' ', sizeof (t
.buf
) - 8 - 4 * 4);
357 __attribute__ ((noinline
))
361 struct T
{ char buf
[64]; char buf2
[64]; } t
;
362 char *p
= &buf
[64], *q
= &t
.buf
[64];
364 if (__builtin_object_size (p
+ 64, 3) != 0)
366 if (__builtin_object_size (q
+ 0, 3) != 0)
368 if (__builtin_object_size (q
+ 64, 3) != 0)
373 __attribute__ ((noinline
))
376 struct T
{ char buf
[10]; char buf2
[10]; } t
;
377 char *p
= &t
.buf2
[-4];
378 char *q
= &t
.buf2
[0];
379 if (__builtin_object_size (p
, 3) != 0)
381 if (__builtin_object_size (q
, 3) != sizeof (t
.buf2
))
384 if (__builtin_object_size (q
, 3) != 0)
387 if (__builtin_object_size (q
, 3) != 0)
390 if (__builtin_object_size (p
, 3) != 0)
398 __asm ("" : "=r" (l1
) : "0" (l1
));
402 test4 ((char *) s
, 10);