Debian Codegraph @

gcc/testsuite/gcc.dg/nested-vla-1.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-std=gnu99" } */
3 /* { dg-require-effective-target trampolines } */
4
5
6 int main()
7 {
8 int n = 1;
9
10 struct foo { char x[++n]; } bar(void) { struct foo r; return r; }
11
12 if (2 != n)
13 __builtin_abort();
14
15 if (2 != sizeof(bar()))
16 __builtin_abort();
17
18 n = 1;
19
20 struct bar { char x[++n]; } (*bar2p)(void);
21 struct bar bar2(void) { struct bar r; return r; }
22 bar2p = &bar2;
23
24 if (2 != n)
25 __builtin_abort();
26
27 if (2 != sizeof((*bar2p)()))
28 __builtin_abort();
29
30 n = 1;
31
32 struct str { char x[++n]; } *bar3(void)
33 {
34 struct str* s = __builtin_malloc(sizeof(struct str));
35 if (!s)
36 __builtin_abort();
37 struct str t;
38 *s = t;
39 return s;
40 }
41
42 if (2 != n)
43 __builtin_abort();
44
45 struct str* p;
46
47 if (2 != sizeof(*(p = bar3())))
48 __builtin_abort();
49
50 __builtin_free(p);
51
52 n = 1;
53
54 struct { char x[++n]; } *bar4(void) { }
55
56 if (2 != n)
57 __builtin_abort();
58 #if 0
59 // UB
60 if (2 != sizeof(*bar4()))
61 __builtin_abort();
62 #endif
63 }
64