Skip to content

Commit 935a2eb

Browse files
author
Daniel Kroening
committed
test for bit-field promotion (#3709)
Usual promotion rules apply to bit-fields -- thus, an unsigned bit-field that is smaller than 'int' gets promoted to 'int', and thus yields a signed expression. Issue #3709.
1 parent 9213145 commit 935a2eb

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

regression/cbmc/Bitfields1/main.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ typedef enum _INTEL_CACHE_TYPE {
88
} INTEL_CACHE_TYPE;
99

1010
struct bft {
11-
unsigned int a:3;
11+
unsigned long int a : 3;
1212
unsigned int b:1;
1313
signed int c:2;
1414
_Bool d : 1;
@@ -20,7 +20,7 @@ struct bft {
2020
INT x:1;
2121

2222
// made of sizeof
23-
unsigned int abc: sizeof(int);
23+
unsigned int abc : sizeof(int) * 8;
2424

2525
// enums are integers!
2626
INTEL_CACHE_TYPE Type : 5;
@@ -53,7 +53,14 @@ int main() {
5353

5454
// assignments have the underlying type
5555
assert(sizeof(bf.d=1)==sizeof(_Bool));
56-
assert(sizeof(bf.a+=1)==sizeof(unsigned));
56+
assert(sizeof(bf.a += 1) == sizeof(unsigned long));
5757

5858
bf.Type=IntelCacheTrace;
59+
60+
// promotion rules apply, and thus, bf.a is signed,
61+
// but bf.abc is unsigned
62+
bf.a = 0;
63+
assert(bf.a - 1 < 0);
64+
bf.abc = 0;
65+
assert(bf.abc - 1 >= 0);
5966
}

regression/cbmc/Bitfields1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
KNOWNBUG
22
main.c
33

44
^EXIT=0$

0 commit comments

Comments
 (0)