Skip to content

Commit 2662f2b

Browse files
committed
Separate and document checking arithmetic ops
Into check_rec_div and check_rec_arithmetic_op.
1 parent 266f00b commit 2662f2b

File tree

1 file changed

+44
-23
lines changed

1 file changed

+44
-23
lines changed

src/analyses/goto_check.cpp

+44-23
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ class goto_checkt
123123
/// sub-expressions
124124
bool check_rec_member(const member_exprt &member, guardt &guard);
125125

126+
/// Check that a division is valid: check for division by zero, overflow and
127+
/// NaN (for floating point numbers).
128+
/// \param div_expr: the expression to be checked
129+
/// \param guard: the condition for the check (unmodified here)
130+
void check_rec_div(const div_exprt &div_expr, guardt &guard);
131+
132+
/// Check that an arithmetic operation is valid: overflow check, NaN-check
133+
/// (for floating point numbers), and pointer overflow check.
134+
/// \param expr: the expression to be checked
135+
/// \param guard: the condition for the check (unmodified here)
136+
void check_rec_arithmetic_op(const exprt &expr, guardt &guard);
137+
126138
void check_rec(const exprt &expr, guardt &guard);
127139
void check(const exprt &expr);
128140

@@ -1598,6 +1610,36 @@ bool goto_checkt::check_rec_member(const member_exprt &member, guardt &guard)
15981610
return false;
15991611
}
16001612

1613+
void goto_checkt::check_rec_div(const div_exprt &div_expr, guardt &guard)
1614+
{
1615+
div_by_zero_check(to_div_expr(div_expr), guard);
1616+
1617+
if(div_expr.type().id() == ID_signedbv)
1618+
integer_overflow_check(div_expr, guard);
1619+
else if(div_expr.type().id() == ID_floatbv)
1620+
{
1621+
nan_check(div_expr, guard);
1622+
float_overflow_check(div_expr, guard);
1623+
}
1624+
}
1625+
1626+
void goto_checkt::check_rec_arithmetic_op(const exprt &expr, guardt &guard)
1627+
{
1628+
if(expr.type().id() == ID_signedbv || expr.type().id() == ID_unsignedbv)
1629+
{
1630+
integer_overflow_check(expr, guard);
1631+
}
1632+
else if(expr.type().id() == ID_floatbv)
1633+
{
1634+
nan_check(expr, guard);
1635+
float_overflow_check(expr, guard);
1636+
}
1637+
else if(expr.type().id() == ID_pointer)
1638+
{
1639+
pointer_overflow_check(expr, guard);
1640+
}
1641+
}
1642+
16011643
void goto_checkt::check_rec(const exprt &expr, guardt &guard)
16021644
{
16031645
// we don't look into quantifiers
@@ -1637,15 +1679,7 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard)
16371679
}
16381680
else if(expr.id()==ID_div)
16391681
{
1640-
div_by_zero_check(to_div_expr(expr), guard);
1641-
1642-
if(expr.type().id()==ID_signedbv)
1643-
integer_overflow_check(expr, guard);
1644-
else if(expr.type().id()==ID_floatbv)
1645-
{
1646-
nan_check(expr, guard);
1647-
float_overflow_check(expr, guard);
1648-
}
1682+
check_rec_div(to_div_expr(expr), guard);
16491683
}
16501684
else if(expr.id()==ID_shl || expr.id()==ID_ashr || expr.id()==ID_lshr)
16511685
{
@@ -1663,20 +1697,7 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard)
16631697
expr.id()==ID_mult ||
16641698
expr.id()==ID_unary_minus)
16651699
{
1666-
if(expr.type().id()==ID_signedbv ||
1667-
expr.type().id()==ID_unsignedbv)
1668-
{
1669-
integer_overflow_check(expr, guard);
1670-
}
1671-
else if(expr.type().id()==ID_floatbv)
1672-
{
1673-
nan_check(expr, guard);
1674-
float_overflow_check(expr, guard);
1675-
}
1676-
else if(expr.type().id()==ID_pointer)
1677-
{
1678-
pointer_overflow_check(expr, guard);
1679-
}
1700+
check_rec_arithmetic_op(expr, guard);
16801701
}
16811702
else if(expr.id()==ID_typecast)
16821703
conversion_check(expr, guard);

0 commit comments

Comments
 (0)