2 bitfld-1-1.c from the execute part of the gcc torture tests.
11 /* Copyright 2002 Free Software Foundation, Inc.
13 Tests correct signedness of operations on bitfields; in particular
14 that integer promotions are done correctly, including the case when
17 The C front end was eliding the cast of an unsigned bitfield to
18 unsigned as a no-op, when in fact it forces a conversion to a
19 full-width unsigned int. (At the time of writing, the C++ front end
20 has a different bug; it erroneously promotes the uncast unsigned
21 bitfield to an unsigned int).
23 Source: Neil Booth, 25 Jan 2002, based on PR 3325 (and 3326, which
24 is a different manifestation of the same bug).
30 testTortureExecute (void)
32 struct x
{ signed int i
: 7; unsigned int u
: 7; } bit
;
36 unsigned int unsigned_result
= -13U % 61;
37 int signed_result
= -13 % 61;
42 if (i
% u
!= unsigned_result
)
44 if (i
% (unsigned int) u
!= unsigned_result
)
47 /* Somewhat counter-intuitively, bit.u is promoted to an int, making
48 the operands and result an int. */
49 if (i
% bit
.u
!= signed_result
)
52 if (bit
.i
% bit
.u
!= signed_result
)
55 /* But with a cast to unsigned int, the unsigned int is promoted to
56 itself as a no-op, and the operands and result are unsigned. */
57 if (i
% (unsigned int) bit
.u
!= unsigned_result
)
60 if (bit
.i
% (unsigned int) bit
.u
!= unsigned_result
)