Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/util/expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions unit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
39 changes: 39 additions & 0 deletions unit/util/expr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************\

Module: Unit test for expr.h/expr.cpp

Author: Diffblue Ltd

\*******************************************************************/

#include <testing-utils/catch.hpp>

#include <util/arith_tools.h>
#include <util/expr.h>
#include <util/std_expr.h>
#include <util/std_types.h>


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());
}
}
}