libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / pr106465.c
blob0c351a513a148452fd25751e7ad09e9d587bfbd4
1 /* PR c/106465
2 * { dg-do run }
3 * { dg-options "-std=gnu99" }
4 * */
6 int main()
8 int n = 3;
10 void* p = __builtin_malloc(sizeof(struct { char p[16]; }));
12 if (!p)
13 return 0;
15 void g1(int m, struct foo { char p[++m]; }* b) /* { dg-warning "struct" } */
17 if (3 != m)
18 __builtin_abort();
20 struct foo t;
21 *b = t;
23 if (3 != sizeof(b->p))
24 __builtin_abort();
27 void g2(struct { char p[++n]; }* b) /* { dg-warning "anonymous struct" } */
29 if (4 != n)
30 __builtin_abort();
32 typeof(*b) t;
33 *b = t;
35 if (4 != sizeof(b->p))
36 __builtin_abort();
39 void g2b(struct { char (*p)[++n]; }* b) /* { dg-warning "anonymous struct" } */
41 if (5 != n)
42 __builtin_abort();
44 char tmp[5];
45 typeof(*b) t = { &tmp };
46 *b = t;
48 if (5 != sizeof(*b->p))
49 __builtin_abort();
52 if (3 != n)
53 __builtin_abort();
55 g1(2, p);
56 g2(p);
57 g2b(p);
58 n--;
60 __builtin_free(p);
62 if (4 != n)
63 __builtin_abort();
65 struct foo { char (*p)[++n]; } x;
67 if (5 != n)
68 __builtin_abort();
70 char tmp1[5];
71 x.p = &tmp1;
73 struct bar { char (*p)[++n]; };
75 if (6 != n)
76 __builtin_abort();
78 auto struct z { char (*p)[++n]; } g3(void);
80 if (7 != n)
81 __builtin_abort();
83 struct z g3(void) { };
85 if (7 != n)
86 __builtin_abort();
88 struct { char (*p)[++n]; } g4(void) { };
90 if (8 != n)
91 __builtin_abort();
93 __auto_type u = g3();
95 if (8 != n)
96 __builtin_abort();
98 char tmp2[7];
99 u.p = &tmp2;
101 if (5 != sizeof *x.p)
102 __builtin_abort();
104 if (7 != sizeof *u.p)
105 __builtin_abort();
107 return 0;