Skip to content

Commit 1b93b0f

Browse files
authored
Merge pull request #3713 from diffblue/bitfield-promotion
test for bitfield promotion
2 parents 19385d0 + 935a2eb commit 1b93b0f

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

regression/cbmc/Bitfields1/main.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ 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;
14-
_Bool d:3;
14+
_Bool d : 1;
1515

1616
// an anonymous bitfield
1717
signed int :2;
@@ -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)