@@ -123,6 +123,18 @@ class goto_checkt
123
123
// / sub-expressions
124
124
bool check_rec_member (const member_exprt &member, guardt &guard);
125
125
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
+
126
138
void check_rec (const exprt &expr, guardt &guard);
127
139
void check (const exprt &expr);
128
140
@@ -1598,6 +1610,36 @@ bool goto_checkt::check_rec_member(const member_exprt &member, guardt &guard)
1598
1610
return false ;
1599
1611
}
1600
1612
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
+
1601
1643
void goto_checkt::check_rec (const exprt &expr, guardt &guard)
1602
1644
{
1603
1645
// we don't look into quantifiers
@@ -1637,15 +1679,7 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard)
1637
1679
}
1638
1680
else if (expr.id ()==ID_div)
1639
1681
{
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);
1649
1683
}
1650
1684
else if (expr.id ()==ID_shl || expr.id ()==ID_ashr || expr.id ()==ID_lshr)
1651
1685
{
@@ -1663,20 +1697,7 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard)
1663
1697
expr.id ()==ID_mult ||
1664
1698
expr.id ()==ID_unary_minus)
1665
1699
{
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);
1680
1701
}
1681
1702
else if (expr.id ()==ID_typecast)
1682
1703
conversion_check (expr, guard);
0 commit comments