Debian Codegraph @

gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos-1.c

raw
1 /* testing flexible array members in unions and alone in structures:
2 __bos/__bdos */
3 /* { dg-do run } */
4 /* { dg-options "-O2" } */
5
6 union with_fam_1 {
7 char a;
8 int b[];
9 } *with_fam_1_v;
10
11 union with_fam_2 {
12 int a;
13 char b[];
14 } *with_fam_2_v;
15
16 union with_fam_3 {
17 char a[];
18 int b[];
19 } *with_fam_3_v;
20
21 struct only_fam {
22 int b[];
23 } *only_fam_v;
24
25 struct only_fam_2 {
26 unsigned int : 2;
27 unsigned int : 3;
28 int b[];
29 } *only_fam_2_v;
30
31 void __attribute__((__noinline__))
32 setup (int n1, int n2, int n3, int n4, int n5)
33 {
34 with_fam_1_v = (union with_fam_1 *) __builtin_malloc (n1 * sizeof (int));
35 with_fam_2_v = (union with_fam_2 *) __builtin_malloc (n2 * sizeof (char));
36 with_fam_3_v = (union with_fam_3 *) __builtin_malloc (n3 * sizeof (int));
37 only_fam_v = (struct only_fam *) __builtin_malloc (n4 * sizeof (int));
38 only_fam_2_v = (struct only_fam_2 *) __builtin_malloc (n5 * sizeof (int));
39 return;
40 }
41
42 void __attribute__((__noinline__)) stuff(
43 union with_fam_1 *with_fam_1_v,
44 union with_fam_2 *with_fam_2_v,
45 union with_fam_3 *with_fam_3_v,
46 struct only_fam *only_fam_v,
47 struct only_fam_2 *only_fam_2_v)
48 {
49 if (__builtin_object_size(with_fam_1_v->b, 1) != -1)
50 __builtin_abort ();
51 if (__builtin_object_size(with_fam_2_v->b, 1) != -1)
52 __builtin_abort ();
53 if (__builtin_object_size(with_fam_3_v->b, 1) != -1)
54 __builtin_abort ();
55 if (__builtin_object_size(only_fam_v->b, 1) != -1)
56 __builtin_abort ();
57 if (__builtin_object_size(only_fam_2_v->b, 1) != -1)
58 __builtin_abort ();
59 }
60
61 int main (int argc, char *argv[])
62 {
63 setup (2, 3, 4, 5, 6);
64 stuff (with_fam_1_v, with_fam_2_v, with_fam_3_v, only_fam_v, only_fam_2_v);
65 return 0;
66 }