Debian Codegraph @

gcc/testsuite/gcc.dg/bitint-17.c

raw
1 /* PR c/102989 */
2 /* { dg-do compile { target bitint } } */
3 /* { dg-options "-O2 -std=c23 -pedantic-errors" } */
4
5 #define expr_has_type(e, t) _Generic (e, default : 0, t : 1)
6
7 struct S1 { char x; char : 0; char y; };
8 struct S2 { char x; int : 0; char y; };
9 #if __BITINT_MAXWIDTH__ >= 575
10 struct S3 { char x; _BitInt(575) : 0; char y; };
11 #endif
12 #if __BITINT_MAXWIDTH__ >= 389
13 struct S4 { char x; _BitInt(195) a : 63; _BitInt(282) b : 280; _BitInt(389) c : 23; _BitInt(2) d : 1; char y; };
14 #endif
15 #if __BITINT_MAXWIDTH__ >= 192
16 struct S5 { char x; _BitInt(192) a : 191; unsigned _BitInt(192) b : 190; _BitInt(192) c : 189; char y; };
17 #endif
18 struct S6 { _BitInt(2) a : 1; };
19 #if __BITINT_MAXWIDTH__ >= 389
20 struct S4 s4;
21 static_assert (expr_has_type (s4.a + 1uwb, _BitInt(195)));
22 static_assert (expr_has_type (s4.b + 1uwb, _BitInt(282)));
23 static_assert (expr_has_type (s4.c + 1uwb, _BitInt(389)));
24 static_assert (expr_has_type (s4.d * 0wb, _BitInt(2)));
25 #endif
26 #if __BITINT_MAXWIDTH__ >= 192
27 struct S5 s5;
28 static_assert (expr_has_type (s5.a + 1uwb, _BitInt(192)));
29 static_assert (expr_has_type (s5.b + 1wb, unsigned _BitInt(192)));
30 static_assert (expr_has_type (s5.c + 1uwb, _BitInt(192)));
31 #endif
32 struct S6 s6;
33 static_assert (expr_has_type (s6.a + 0wb, _BitInt(2)));
34 #if defined(__x86_64__) && __LP64__ && __BITINT_MAXWIDTH__ >= 575
35 static_assert (sizeof (struct S1) == 2);
36 static_assert (sizeof (struct S2) == 5);
37 static_assert (sizeof (struct S3) == 9);
38 static_assert (sizeof (struct S4) == 48);
39 static_assert (sizeof (struct S5) == 88);
40 static_assert (sizeof (struct S6) == 1);
41 static_assert (alignof (struct S1) == 1);
42 static_assert (alignof (struct S2) == 1);
43 static_assert (alignof (struct S3) == 1);
44 static_assert (alignof (struct S4) == 8);
45 static_assert (alignof (struct S5) == 8);
46 static_assert (alignof (struct S6) == 1);
47 #endif