Skip to content

Commit ce2b514

Browse files
Make exprt::is_zero() support bitfields
1 parent f6c34f2 commit ce2b514

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/util/expr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ bool exprt::is_zero() const
178178
}
179179
else if(type_id==ID_unsignedbv ||
180180
type_id==ID_signedbv ||
181-
type_id==ID_c_bool)
181+
type_id==ID_c_bool ||
182+
type_id==ID_c_bit_field)
182183
{
183184
return constant.value_is_zero_string();
184185
}

unit/util/expr.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*******************************************************************\
2+
3+
Module: Unit test for expr.h/expr.cpp
4+
5+
Author: Diffblue Ltd
6+
7+
\*******************************************************************/
8+
9+
#include <testing-utils/catch.hpp>
10+
11+
#include <util/expr.h>
12+
#include <util/std_types.h>
13+
#include <util/std_expr.h>
14+
#include <util/arith_tools.h>
15+
16+
17+
SCENARIO("bitfield-expr-is-zero", "[core][util][expr]")
18+
{
19+
GIVEN("An exprt representing a bitfield constant of 3")
20+
{
21+
const exprt bitfield3 = from_integer(mp_integer(3), c_bit_field_typet(signedbv_typet(32), 4));
22+
23+
THEN("is_zero() should be false")
24+
{
25+
REQUIRE(!bitfield3.is_zero());
26+
}
27+
}
28+
GIVEN("An exprt representing a bitfield constant of 0")
29+
{
30+
const exprt bitfield0 = from_integer(mp_integer(0), c_bit_field_typet(signedbv_typet(32), 4));
31+
32+
THEN("is_zero() should be true")
33+
{
34+
REQUIRE(bitfield0.is_zero());
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)