diff --git a/src/util/expr.cpp b/src/util/expr.cpp index af2cff9946fb..8104e65e4de6 100644 --- a/src/util/expr.cpp +++ b/src/util/expr.cpp @@ -178,7 +178,8 @@ bool exprt::is_zero() const } else if(type_id==ID_unsignedbv || type_id==ID_signedbv || - type_id==ID_c_bool) + type_id==ID_c_bool || + type_id==ID_c_bit_field) { return constant.value_is_zero_string(); } diff --git a/unit/Makefile b/unit/Makefile index 1f92f2be2d62..f0a5bb294cdf 100644 --- a/unit/Makefile +++ b/unit/Makefile @@ -24,6 +24,7 @@ SRC += unit_tests.cpp \ solvers/refinement/string_refinement/substitute_array_list.cpp \ solvers/refinement/string_refinement/sparse_array.cpp \ solvers/refinement/string_refinement/union_find_replace.cpp \ + util/expr.cpp \ util/expr_cast/expr_cast.cpp \ util/graph.cpp \ util/irep.cpp \ diff --git a/unit/util/expr.cpp b/unit/util/expr.cpp new file mode 100644 index 000000000000..f340792a7f5a --- /dev/null +++ b/unit/util/expr.cpp @@ -0,0 +1,37 @@ +/*******************************************************************\ + +Module: Unit test for expr.h/expr.cpp + +Author: Diffblue Ltd + +\*******************************************************************/ + +#include + +#include +#include +#include +#include + + +SCENARIO("bitfield-expr-is-zero", "[core][util][expr]") +{ + GIVEN("An exprt representing a bitfield constant of 3") + { + const exprt bitfield3 = from_integer(mp_integer(3), c_bit_field_typet(signedbv_typet(32), 4)); + + THEN("is_zero() should be false") + { + REQUIRE(!bitfield3.is_zero()); + } + } + GIVEN("An exprt representing a bitfield constant of 0") + { + const exprt bitfield0 = from_integer(mp_integer(0), c_bit_field_typet(signedbv_typet(32), 4)); + + THEN("is_zero() should be true") + { + REQUIRE(bitfield0.is_zero()); + } + } +}