| 1 |
/* PR c/102989 */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-std=c23 -pedantic-errors" } */ |
| 4 |
|
| 5 |
#define expr_has_type(e, t) _Generic (e, default : 0, t : 1) |
| 6 |
|
| 7 |
#ifdef __BITINT_MAXWIDTH__ |
| 8 |
void |
| 9 |
foo (void) |
| 10 |
{ |
| 11 |
_BitInt(42) a = (_BitInt(42)) 1; |
| 12 |
_BitInt(42) unsigned b = (unsigned _BitInt(42)) 2; |
| 13 |
_BitInt(5) c = (_BitInt(5)) 3; |
| 14 |
_BitInt(5) unsigned d = (unsigned _BitInt(5)) 4; |
| 15 |
_BitInt(32) e = (_BitInt(32)) 5; |
| 16 |
_BitInt(32) unsigned f = (unsigned _BitInt(32)) 6; |
| 17 |
constexpr int g = 43; |
| 18 |
enum E { F = 44 }; |
| 19 |
_BitInt(g) h; |
| 20 |
unsigned _BitInt(F) i; |
| 21 |
static_assert (expr_has_type (a, signed _BitInt(42)), ""); |
| 22 |
static_assert (expr_has_type (a, _BitInt(42)), ""); |
| 23 |
static_assert (!expr_has_type (a, unsigned _BitInt(42)), ""); |
| 24 |
static_assert (!expr_has_type (b, signed _BitInt(42)), ""); |
| 25 |
static_assert (!expr_has_type (b, _BitInt(42)), ""); |
| 26 |
static_assert (expr_has_type (b, unsigned _BitInt(42)), ""); |
| 27 |
static_assert (expr_has_type (a + b, unsigned _BitInt(42)), ""); |
| 28 |
static_assert (expr_has_type (a * b, unsigned _BitInt(42)), ""); |
| 29 |
static_assert (expr_has_type (a - b, unsigned _BitInt(42)), ""); |
| 30 |
static_assert (expr_has_type (a * a, _BitInt(42)), ""); |
| 31 |
static_assert (expr_has_type (a / b, unsigned _BitInt(42)), ""); |
| 32 |
static_assert (expr_has_type (c, signed _BitInt(5)), ""); |
| 33 |
static_assert (expr_has_type (c, _BitInt(5)), ""); |
| 34 |
static_assert (!expr_has_type (c, unsigned _BitInt(5)), ""); |
| 35 |
static_assert (!expr_has_type (d, signed _BitInt(5)), ""); |
| 36 |
static_assert (!expr_has_type (d, _BitInt(5)), ""); |
| 37 |
static_assert (expr_has_type (d, unsigned _BitInt(5)), ""); |
| 38 |
static_assert (expr_has_type (c + d, unsigned _BitInt(5)), ""); |
| 39 |
static_assert (expr_has_type (c * d, unsigned _BitInt(5)), ""); |
| 40 |
static_assert (expr_has_type (c - d, unsigned _BitInt(5)), ""); |
| 41 |
static_assert (expr_has_type (c * c, _BitInt(5)), ""); |
| 42 |
static_assert (expr_has_type (c / d, unsigned _BitInt(5)), ""); |
| 43 |
static_assert (expr_has_type (e, signed _BitInt(32)), ""); |
| 44 |
static_assert (expr_has_type (e, _BitInt(32)), ""); |
| 45 |
static_assert (!expr_has_type (e, unsigned _BitInt(32)), ""); |
| 46 |
static_assert (!expr_has_type (f, signed _BitInt(32)), ""); |
| 47 |
static_assert (!expr_has_type (f, _BitInt(32)), ""); |
| 48 |
static_assert (expr_has_type (f, unsigned _BitInt(32)), ""); |
| 49 |
static_assert (expr_has_type (e + f, unsigned _BitInt(32)), ""); |
| 50 |
static_assert (expr_has_type (e * f, unsigned _BitInt(32)), ""); |
| 51 |
static_assert (expr_has_type (e - f, unsigned _BitInt(32)), ""); |
| 52 |
static_assert (expr_has_type (e * e, _BitInt(32)), ""); |
| 53 |
static_assert (expr_has_type (e / f, unsigned _BitInt(32)), ""); |
| 54 |
#if __CHAR_BIT__ * __SIZEOF_INT__ == 32 |
| 55 |
static_assert (expr_has_type (e + 1, int), ""); |
| 56 |
static_assert (expr_has_type (f + 1, unsigned int), ""); |
| 57 |
static_assert (expr_has_type (e + 1U, unsigned int), ""); |
| 58 |
static_assert (expr_has_type (f + 1U, unsigned int), ""); |
| 59 |
static_assert (expr_has_type (1 - e, int), ""); |
| 60 |
static_assert (expr_has_type (1 - f, unsigned int), ""); |
| 61 |
static_assert (expr_has_type (1U * e, unsigned int), ""); |
| 62 |
static_assert (expr_has_type (1U / f, unsigned int), ""); |
| 63 |
#endif |
| 64 |
static_assert (expr_has_type (0wb, _BitInt(2)), ""); |
| 65 |
static_assert (expr_has_type (-1WB, _BitInt(2)), ""); |
| 66 |
static_assert (expr_has_type (-1wb - 1wb, _BitInt(2)), ""); |
| 67 |
static_assert (expr_has_type (1wb, _BitInt(2)), ""); |
| 68 |
static_assert (expr_has_type (2wb, _BitInt(3)), ""); |
| 69 |
static_assert (expr_has_type (0wbu, unsigned _BitInt(1)), ""); |
| 70 |
static_assert (expr_has_type (-1UWB, unsigned _BitInt(1)), ""); |
| 71 |
static_assert (expr_has_type (1uWB, unsigned _BitInt(1)), ""); |
| 72 |
static_assert (expr_has_type (2Uwb, unsigned _BitInt(2)), ""); |
| 73 |
static_assert (expr_has_type (h, signed _BitInt(43)), ""); |
| 74 |
static_assert (expr_has_type (i, unsigned _BitInt(44)), ""); |
| 75 |
static_assert (0wb == 0, ""); |
| 76 |
static_assert (-1wb == -1, ""); |
| 77 |
static_assert (0xffffffffwb == 4294967295wb, ""); |
| 78 |
static_assert (0xffffffffwb == 000000000000000000000000000037777777777wb, ""); |
| 79 |
static_assert (0x0000000000000000000000000ffffffffwb == 0b00011111111111111111111111111111111wb, ""); |
| 80 |
#if __BITINT_MAXWIDTH__ >= 128 |
| 81 |
static_assert (expr_has_type (0xffffffffffffffffffffffffffffffffuwb, unsigned _BitInt(128)), ""); |
| 82 |
static_assert (0xffffffffffffffffffffffffffffffffuwb == 340282366920938463463374607431768211455uwb, ""); |
| 83 |
static_assert (200000000000000000000000000000000000000wb == 0x96769950b50d88f41314448000000000WB, ""); |
| 84 |
static_assert (02263551452055206610750114242110000000000000wb == 200000000000000000000000000000000000000wb, ""); |
| 85 |
#endif |
| 86 |
#if __BITINT_MAXWIDTH__ >= 575 |
| 87 |
static_assert (expr_has_type (123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567UWB, unsigned _BitInt(575)), ""); |
| 88 |
static_assert (expr_has_type (0x00000007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwbu, unsigned _BitInt(575)), ""); |
| 89 |
static_assert (expr_has_type (0377777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777uwb, unsigned _BitInt(575)), ""); |
| 90 |
static_assert (123665200736552267030251260509823595017565674550605919957031528046448612553265933585158200530621522494798835713008069669675682517153375604983773077550946583958303386074349567uwb == 0x00000007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwbu, ""); |
| 91 |
static_assert (0377777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777WBU == 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffuWB, ""); |
| 92 |
static_assert (100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000uwb == 0X67815961'0903F797'4A7CB3F2'2F01FA5D'9A2CD603'9DE4A7A6'0F713676'CE7D7113'FF1A499D'9BFD0FDC'D2999652'EB4C7F39'8DE2A000'00000000'00000000'00000000'00000000'00000000UWB, ""); |
| 93 |
static_assert (expr_has_type (-61'832600368'276133515'125630254'911797508'782837275'302959978'515764023'224306276'632966792'579100265'310761247'399417856'504034834'837841258'576687802'491886538'775473291'979151693'037174783wb, _BitInt(575)), ""); |
| 94 |
static_assert (expr_has_type (0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwb, signed _BitInt(575)), ""); |
| 95 |
static_assert (expr_has_type (0177777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777wb, _BitInt(575)), ""); |
| 96 |
static_assert (-61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783WB == -0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwb, ""); |
| 97 |
static_assert (0177777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777wb / 2wb * 2wb + 1wb == 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwb, ""); |
| 98 |
#endif |
| 99 |
#if (0wb != 0) || (0wbU != 0U) || (1wb != 1) || (1uWB != 1u) \ |
| 100 |
|| (-1wb >= 0) || (-1UWB < 0) || (4294967295uwb != 4294967295U) \ |
| 101 |
|| 18446744073709551615wbu != 18446744073709551615ULL |
| 102 |
#error "" |
| 103 |
#endif |
| 104 |
} |
| 105 |
|
| 106 |
void |
| 107 |
bar (void) |
| 108 |
{ |
| 109 |
_BitInt(2) a = (_BitInt(2)) 1; |
| 110 |
unsigned _BitInt(1) b = 1uwb; |
| 111 |
_BitInt(4) c; |
| 112 |
c = 7; |
| 113 |
_BitInt(2) d = 1; |
| 114 |
_BitInt(5) e = 2wb; |
| 115 |
unsigned _BitInt(6) f = 3uwb; |
| 116 |
} |
| 117 |
#endif |
| 118 |
|
| 119 |
int |
| 120 |
main () |
| 121 |
{ |
| 122 |
} |