1 /* Copyright 2002 Free Software Foundation, Inc.
3 Tests correct signedness of operations on bitfields; in particular
4 that integer promotions are done correctly, including the case when
7 The C front end was eliding the cast of an unsigned bitfield to
8 unsigned as a no-op, when in fact it forces a conversion to a
9 full-width unsigned int. (At the time of writing, the C++ front end
10 has a different bug; it erroneously promotes the uncast unsigned
11 bitfield to an unsigned int).
13 Source: Neil Booth, 25 Jan 2002, based on PR 3325 (and 3326, which
14 is a different manifestation of the same bug).
20 main(int argc
, char *argv
[])
22 struct x
{ signed int i
: 7; unsigned int u
: 7; } bit
;
26 unsigned int unsigned_result
= -13U % 61;
27 int signed_result
= -13 % 61;
32 if (i
% u
!= unsigned_result
)
34 if (i
% (unsigned int) u
!= unsigned_result
)
37 /* Somewhat counter-intuitively, bit.u is promoted to an int, making
38 the operands and result an int. */
39 if (i
% bit
.u
!= signed_result
)
42 if (bit
.i
% bit
.u
!= signed_result
)
45 /* But with a cast to unsigned int, the unsigned int is promoted to
46 itself as a no-op, and the operands and result are unsigned. */
47 if (i
% (unsigned int) bit
.u
!= unsigned_result
)
50 if (bit
.i
% (unsigned int) bit
.u
!= unsigned_result
)