Debian Codegraph @

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

raw
1 /* testing the correct usage of flexible array members in unions
2 and alone in structures: initialization */
3 /* { dg-do run } */
4 /* { dg-options "-O2" } */
5
6 union with_fam_1 {
7 int a;
8 int b[];
9 } with_fam_1_v = {.b = {1, 2, 3, 4}};
10
11 union with_fam_2 {
12 int a;
13 char b[];
14 } with_fam_2_v = {.a = 0x1f2f3f4f};
15
16 union with_fam_3 {
17 unsigned char a[];
18 int b[];
19 } with_fam_3_v = {.b = {0x1f2f3f4f, 0x5f6f7f8f}};
20
21 struct only_fam {
22 int b[];
23 } only_fam_v = {{7, 11}};
24
25 struct only_fam_2 {
26 unsigned int : 2;
27 unsigned int : 3;
28 int b[];
29 } only_fam_2_v = {{7, 11}};
30
31 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
32 #define WITH_FAM_2_V_B0 0x4f
33 #define WITH_FAM_2_V_B3 0x1f
34 #define WITH_FAM_3_V_A0 0x4f
35 #define WITH_FAM_3_V_A7 0x5f
36 #else
37 #define WITH_FAM_2_V_B0 0x1f
38 #define WITH_FAM_2_V_B3 0x4f
39 #define WITH_FAM_3_V_A0 0x1f
40 #define WITH_FAM_3_V_A7 0x8f
41 #endif
42
43 int main ()
44 {
45 if (with_fam_1_v.b[3] != 4
46 || with_fam_1_v.b[0] != 1)
47 __builtin_abort ();
48 if (with_fam_2_v.b[3] != WITH_FAM_2_V_B3
49 || with_fam_2_v.b[0] != WITH_FAM_2_V_B0)
50 __builtin_abort ();
51 if (with_fam_3_v.a[0] != WITH_FAM_3_V_A0
52 || with_fam_3_v.a[7] != WITH_FAM_3_V_A7)
53 __builtin_abort ();
54 if (only_fam_v.b[0] != 7
55 || only_fam_v.b[1] != 11)
56 __builtin_abort ();
57 if (only_fam_2_v.b[0] != 7
58 || only_fam_2_v.b[1] != 11)
59 __builtin_abort ();
60
61 return 0;
62 }
63