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
, 1) != sizeof (a
.a
) - 3)
40 if (__builtin_object_size (&a
.c
[9], 1)
43 if (__builtin_object_size (q
, 1) != (size_t) -1)
45 if (__builtin_object_size (r
, 1) != sizeof (a
.c
) - 1)
51 if (__builtin_object_size (&y
, 1) != sizeof (y
))
53 if (__builtin_object_size (w
, 1) != sizeof (w
))
55 if (__builtin_object_size (&y
.b
, 1) != sizeof (a
.b
))
57 if (__builtin_object_size (r
, 1) != sizeof (a
.a
) - 1)
63 if (__builtin_object_size (r
, 1) != 2 * 16)
69 if (__builtin_object_size (r
, 1) != 30)
72 r
= malloc (sizeof (a
));
75 if (__builtin_object_size (r
, 1) != sizeof (a
))
77 r
= memcpy (r
, "a", 2);
78 if (__builtin_object_size (r
, 1) != sizeof (a
))
80 r
= memcpy (r
+ 2, "b", 2) + 2;
81 if (__builtin_object_size (r
, 1) != sizeof (a
) - 4)
84 r
= memset (r
, 'a', 2);
85 if (__builtin_object_size (r
, 1) != sizeof (a
.a
) - 4)
87 r
= memset (r
+ 2, 'b', 2) + 2;
88 if (__builtin_object_size (r
, 1) != sizeof (a
.a
) - 8)
92 if (__builtin_object_size (r
, 1) != sizeof (a
.a
) - 1)
94 r
= strcpy (r
+ 2, "cd") + 2;
95 if (__builtin_object_size (r
, 1) != sizeof (a
.a
) - 5)
97 if (__builtin_object_size (exta
, 1) != (size_t) -1)
99 if (__builtin_object_size (exta
+ 10, 1) != (size_t) -1)
101 if (__builtin_object_size (&exta
[5], 1) != (size_t) -1)
103 if (__builtin_object_size (extb
, 1) != sizeof (extb
))
105 if (__builtin_object_size (extb
+ 10, 1) != sizeof (extb
) - 10)
107 if (__builtin_object_size (&extb
[5], 1) != sizeof (extb
) - 5)
109 if (__builtin_object_size (extc
, 1) != (size_t) -1)
111 if (__builtin_object_size (extc
+ 10, 1) != (size_t) -1)
113 if (__builtin_object_size (&extc
[5], 1) != (size_t) -1)
115 if (__builtin_object_size (&extc
->a
, 1) != (size_t) -1)
117 if (__builtin_object_size (&(extc
+ 10)->b
, 1) != (size_t) -1)
119 if (__builtin_object_size (&extc
[5].c
[3], 1) != (size_t) -1)
121 if (__builtin_object_size (var
, 1) != (size_t) -1)
123 if (__builtin_object_size (var
+ 10, 1) != (size_t) -1)
125 if (__builtin_object_size (&var
[5], 1) != (size_t) -1)
127 if (__builtin_object_size (vara
, 1) != (size_t) -1)
129 if (__builtin_object_size (vara
+ 10, 1) != (size_t) -1)
131 if (__builtin_object_size (&vara
[5], 1) != (size_t) -1)
133 if (__builtin_object_size (&vara
[0].a
, 1) != sizeof (vara
[0].a
))
135 if (__builtin_object_size (&vara
[10].a
[0], 1) != sizeof (vara
[0].a
))
137 if (__builtin_object_size (&vara
[5].a
[4], 1) != sizeof (vara
[0].a
) - 4)
139 if (__builtin_object_size (&vara
[5].b
, 1) != sizeof (vara
[0].b
))
141 if (__builtin_object_size (&vara
[7].c
[7], 1) != sizeof (vara
[0].c
) - 7)
143 if (__builtin_object_size (zerol
, 1) != 0)
145 if (__builtin_object_size (&zerol
, 1) != 0)
147 if (__builtin_object_size (&zerol
[0], 1) != 0)
149 if (__builtin_object_size (zerol
[0].a
, 1) != 0)
151 if (__builtin_object_size (&zerol
[0].a
[0], 1) != 0)
153 if (__builtin_object_size (&zerol
[0].b
, 1) != 0)
155 if (__builtin_object_size ("abcdefg", 1) != sizeof ("abcdefg"))
157 if (__builtin_object_size ("abcd\0efg", 1) != sizeof ("abcd\0efg"))
159 if (__builtin_object_size (&"abcd\0efg", 1) != sizeof ("abcd\0efg"))
161 if (__builtin_object_size (&"abcd\0efg"[0], 1) != sizeof ("abcd\0efg"))
163 if (__builtin_object_size (&"abcd\0efg"[4], 1) != sizeof ("abcd\0efg") - 4)
165 if (__builtin_object_size ("abcd\0efg" + 5, 1) != sizeof ("abcd\0efg") - 5)
167 if (__builtin_object_size (L
"abcdefg", 1) != sizeof (L
"abcdefg"))
169 r
= (char *) L
"abcd\0efg";
170 if (__builtin_object_size (r
+ 2, 1) != 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
, 1) != sizeof (buf3
))
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
, 1) != sizeof (buf3
) - 5)
216 if (__builtin_object_size (r
, 1) != sizeof (buf3
) - 13)
218 if (__builtin_object_size (r
+ 6, 1) != sizeof (buf3
) - 19)
223 __attribute__ ((noinline
))
227 struct B
{ struct A a
[2]; struct A b
; char c
[4]; char d
; double e
;
228 _Complex
double f
; } x
;
233 if (__builtin_object_size (buf4
, 1) != sizeof (buf4
))
235 if (__builtin_object_size (&buf4
, 1) != sizeof (buf4
))
237 if (__builtin_object_size (&buf4
[0], 1) != sizeof (buf4
))
239 if (__builtin_object_size (&buf4
[1], 1) != sizeof (buf4
) - 1)
241 if (__builtin_object_size (&x
, 1) != sizeof (x
))
243 if (__builtin_object_size (&x
.a
, 1) != sizeof (x
.a
))
245 if (__builtin_object_size (&x
.a
[0], 1) != sizeof (x
.a
))
247 if (__builtin_object_size (&x
.a
[0].a
, 1) != sizeof (x
.a
[0].a
))
249 if (__builtin_object_size (&x
.a
[0].a
[0], 1) != sizeof (x
.a
[0].a
))
251 if (__builtin_object_size (&x
.a
[0].a
[3], 1) != sizeof (x
.a
[0].a
) - 3)
253 if (__builtin_object_size (&x
.a
[0].b
, 1) != sizeof (x
.a
[0].b
))
255 if (__builtin_object_size (&x
.a
[1].c
, 1) != sizeof (x
.a
[1].c
))
257 if (__builtin_object_size (&x
.a
[1].c
[0], 1) != sizeof (x
.a
[1].c
))
259 if (__builtin_object_size (&x
.a
[1].c
[3], 1) != sizeof (x
.a
[1].c
) - 3)
261 if (__builtin_object_size (&x
.b
, 1) != sizeof (x
.b
))
263 if (__builtin_object_size (&x
.b
.a
, 1) != sizeof (x
.b
.a
))
265 if (__builtin_object_size (&x
.b
.a
[0], 1) != sizeof (x
.b
.a
))
267 if (__builtin_object_size (&x
.b
.a
[3], 1) != sizeof (x
.b
.a
) - 3)
269 if (__builtin_object_size (&x
.b
.b
, 1) != sizeof (x
.b
.b
))
271 if (__builtin_object_size (&x
.b
.c
, 1) != sizeof (x
.b
.c
))
273 if (__builtin_object_size (&x
.b
.c
[0], 1) != sizeof (x
.b
.c
))
275 if (__builtin_object_size (&x
.b
.c
[3], 1) != sizeof (x
.b
.c
) - 3)
277 if (__builtin_object_size (&x
.c
, 1) != sizeof (x
.c
))
279 if (__builtin_object_size (&x
.c
[0], 1) != sizeof (x
.c
))
281 if (__builtin_object_size (&x
.c
[1], 1) != sizeof (x
.c
) - 1)
283 if (__builtin_object_size (&x
.d
, 1) != sizeof (x
.d
))
285 if (__builtin_object_size (&x
.e
, 1) != sizeof (x
.e
))
287 if (__builtin_object_size (&x
.f
, 1) != sizeof (x
.f
))
290 if (__builtin_object_size (dp
, 1) != sizeof (x
.f
) / 2)
293 if (__builtin_object_size (dp
, 1) != sizeof (x
.f
) / 2)
296 if (__builtin_object_size (dp
, 1) != sizeof (y
))
298 if (__builtin_object_size (&z
, 1) != sizeof (z
))
301 if (__builtin_object_size (dp
, 1) != sizeof (z
) / 2)
304 if (__builtin_object_size (dp
, 1) != sizeof (z
) / 2)
308 struct S
{ unsigned int a
; };
311 __attribute__ ((noinline
))
312 test4 (char *x
, int y
)
317 for (i
= 0; i
< y
; i
++)
321 if (__builtin_object_size (p
, 1) != (size_t) -1)
328 __attribute__ ((noinline
))
331 struct T
{ char buf
[64]; char buf2
[64]; } t
;
335 for (i
= 0; i
< x
; ++i
)
337 if (__builtin_object_size (p
, 1) != sizeof (t
.buf
) - 8)
339 memset (p
, ' ', sizeof (t
.buf
) - 8 - 4 * 4);
343 __attribute__ ((noinline
))
347 struct T
{ char buf
[64]; char buf2
[64]; } t
;
348 char *p
= &buf
[64], *q
= &t
.buf
[64];
350 if (__builtin_object_size (p
+ 64, 1) != 0)
352 if (__builtin_object_size (q
+ 0, 1) != 0)
354 if (__builtin_object_size (q
+ 64, 1) != 0)
359 __attribute__ ((noinline
))
362 struct T
{ char buf
[10]; char buf2
[10]; } t
;
363 char *p
= &t
.buf2
[-4];
364 char *q
= &t
.buf2
[0];
365 if (__builtin_object_size (p
, 1) != 0)
367 if (__builtin_object_size (q
, 1) != sizeof (t
.buf2
))
370 if (__builtin_object_size (q
, 1) != 0)
373 if (__builtin_object_size (q
, 1) != 0)
376 if (__builtin_object_size (p
, 1) != 0)
384 __asm ("" : "=r" (l1
) : "0" (l1
));
388 test4 ((char *) s
, 10);