Debian Codegraph @

gcc/testsuite/gcc.dg/pr106465.c

raw
1 /* PR c/106465
2 * { dg-do run }
3 * { dg-options "-std=gnu99" }
4 * */
5
6 int main()
7 {
8 int n = 3;
9
10 void* p = __builtin_malloc(sizeof(struct { char p[16]; }));
11
12 if (!p)
13 return 0;
14
15 void g1(int m, struct foo { char p[++m]; }* b) /* { dg-warning "struct" } */
16 {
17 if (3 != m)
18 __builtin_abort();
19
20 struct foo t;
21 *b = t;
22
23 if (3 != sizeof(b->p))
24 __builtin_abort();
25 }
26
27 void g2(struct { char p[++n]; }* b) /* { dg-warning "anonymous struct" } */
28 {
29 if (4 != n)
30 __builtin_abort();
31
32 typeof(*b) t;
33 *b = t;
34
35 if (4 != sizeof(b->p))
36 __builtin_abort();
37 }
38
39 void g2b(struct { char (*p)[++n]; }* b) /* { dg-warning "anonymous struct" } */
40 {
41 if (5 != n)
42 __builtin_abort();
43
44 char tmp[5];
45 typeof(*b) t = { &tmp };
46 *b = t;
47
48 if (5 != sizeof(*b->p))
49 __builtin_abort();
50 }
51
52 if (3 != n)
53 __builtin_abort();
54
55 g1(2, p);
56 g2(p);
57 g2b(p);
58 n--;
59
60 __builtin_free(p);
61
62 if (4 != n)
63 __builtin_abort();
64
65 struct foo { char (*p)[++n]; } x;
66
67 if (5 != n)
68 __builtin_abort();
69
70 char tmp1[5];
71 x.p = &tmp1;
72
73 struct bar { char (*p)[++n]; };
74
75 if (6 != n)
76 __builtin_abort();
77
78 auto struct z { char (*p)[++n]; } g3(void);
79
80 if (7 != n)
81 __builtin_abort();
82
83 struct z g3(void) { };
84
85 if (7 != n)
86 __builtin_abort();
87
88 struct { char (*p)[++n]; } g4(void) { };
89
90 if (8 != n)
91 __builtin_abort();
92
93 __auto_type u = g3();
94
95 if (8 != n)
96 __builtin_abort();
97
98 char tmp2[7];
99 u.p = &tmp2;
100
101 if (5 != sizeof *x.p)
102 __builtin_abort();
103
104 if (7 != sizeof *u.p)
105 __builtin_abort();
106
107 return 0;
108 }
109