PR tree-optimization/81303
[official-gcc.git] / gcc / testsuite / gcc.dg / builtin-object-size-9.c
blobf134aaca0d6962fda2970396dbf36af9377ee05e
1 /* { dg-do run } */
2 /* { dg-options "-O2" } */
4 typedef __SIZE_TYPE__ size_t;
5 extern void *malloc (size_t);
6 extern void free (void *);
7 extern void abort (void);
9 union U
11 struct S { int a; int b; } s;
12 int t;
15 struct T
17 int c;
18 char d[1];
21 int
22 main (void)
24 union U *u = malloc (sizeof (struct S) + sizeof (struct T) + 6);
25 struct T *t = (struct T *) (&u->s + 1);
26 if (__builtin_object_size (t->d, 1)
27 != sizeof (struct T) + 6 - __builtin_offsetof (struct T, d))
28 abort ();
29 free (u);
30 return 0;