Skip to content

Commit f5bed4f

Browse files
Merge pull request diffblue#222 from diffblue/issue202-bitfields-enums
Add support for bit field and enums intervals.cpp
2 parents fabfbc5 + 24f5ac6 commit f5bed4f

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct bitfield_struct {
2+
unsigned char byte;
3+
unsigned char bitfield:1;
4+
};
5+
6+
extern struct bitfield_struct bs;
7+
8+
void main(void)
9+
{
10+
bs.byte = 10;
11+
bs.bitfield = 1;
12+
__CPROVER_assert(bs.byte==10, "bs.byte==10");
13+
__CPROVER_assert(bs.bitfield==1, "bs.bitfield==1");
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--function main --variable --structs --interval-values --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main\.assertion\.1\] .* bs\.byte==10: Success
7+
\[main\.assertion\.2\] .* bs\.bitfield==1: Success
8+
--

src/util/interval.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1127,17 +1127,20 @@ bool constant_interval_exprt::is_float(const constant_interval_exprt &interval)
11271127
bool constant_interval_exprt::is_bitvector(const typet &t)
11281128
{
11291129
return t.id() == ID_bv || t.id() == ID_signedbv || t.id() == ID_unsignedbv
1130-
|| t.id() == ID_c_bool;
1130+
|| t.id() == ID_c_bool
1131+
|| (t.id() == ID_c_bit_field && is_bitvector(t.subtype()));
11311132
}
11321133

11331134
bool constant_interval_exprt::is_signed(const typet &t)
11341135
{
1135-
return t.id() == ID_signedbv;
1136+
return t.id() == ID_signedbv
1137+
|| (t.id() == ID_c_bit_field && is_signed(t.subtype()));
11361138
}
11371139

11381140
bool constant_interval_exprt::is_unsigned(const typet &t)
11391141
{
1140-
return t.id() == ID_bv || t.id() == ID_unsignedbv || t.id() == ID_c_bool;
1142+
return t.id() == ID_bv || t.id() == ID_unsignedbv || t.id() == ID_c_bool
1143+
|| t.id() == ID_c_enum || (t.id() == ID_c_bit_field && is_unsigned(t.subtype()));
11411144
}
11421145

11431146
bool constant_interval_exprt::is_signed(const constant_interval_exprt &interval)

0 commit comments

Comments
 (0)