diff --git a/src/util/expr.cpp b/src/util/expr.cpp index af2cff9946f..9c672b1051e 100644 --- a/src/util/expr.cpp +++ b/src/util/expr.cpp @@ -176,9 +176,9 @@ bool exprt::is_zero() const CHECK_RETURN(false); return rat_value.is_zero(); } - else if(type_id==ID_unsignedbv || - type_id==ID_signedbv || - type_id==ID_c_bool) + else if( + type_id == ID_unsignedbv || type_id == ID_signedbv || + 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 1f92f2be2d6..f0a5bb294cd 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 00000000000..2f6d172fa70 --- /dev/null +++ b/unit/util/expr.cpp @@ -0,0 +1,39 @@ +/*******************************************************************\ + +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_FALSE(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()); + } + } +}