Skip to content

Commit 91b9614

Browse files
committed
Address review comments
Will be squashed.
1 parent 214dd18 commit 91b9614

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

src/analyses/goto_check.cpp

+22-34
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class goto_checkt
113113
/// \param expr: the expression to be checked
114114
/// \param guard: the condition for the check (extended with the (negation of
115115
/// the) if-condition for recursively calls)
116-
void check_rec_if(const exprt &expr, guardt &guard);
116+
void check_rec_if(const if_exprt &if_expr, guardt &guard);
117117

118118
/// Check that a member expression is valid:
119119
/// - check the structure this expression is a member of (via pointer of its
@@ -123,13 +123,13 @@ class goto_checkt
123123
/// - check all operands of the expression
124124
/// \param expr: the expression to be checked
125125
/// \param guard: the condition for the check (unmodified here)
126-
void check_rec_member(const exprt &expr, guardt &guard);
126+
void check_rec_member(const member_exprt &member, guardt &guard);
127127

128128
/// Check that a division is valid: check for division by zero, overflow and
129129
/// NaN (for floating point numbers).
130130
/// \param expr: the expression to be checked
131131
/// \param guard: the condition for the check (unmodified here)
132-
void check_rec_div(const exprt &expr, guardt &guard);
132+
void check_rec_div(const div_exprt &div_expr, guardt &guard);
133133

134134
/// Check that an arithmetic operation is valid: overflow check, NaN-check
135135
/// (for floating point numbers), and pointer overflow check.
@@ -1486,7 +1486,7 @@ void goto_checkt::add_guarded_claim(
14861486
// add the guard
14871487
exprt guarded_expr =
14881488
guard.is_true()
1489-
? simplified_expr
1489+
? std::move(simplified_expr)
14901490
: implies_exprt{guard.as_expr(), std::move(simplified_expr)};
14911491

14921492
if(assertions.insert(guarded_expr).second)
@@ -1544,16 +1544,14 @@ void goto_checkt::check_rec_logical_op(const exprt &expr, guardt &guard)
15441544
op.pretty());
15451545

15461546
check_rec(op, guard);
1547-
guard.add(expr.id() == ID_or ? not_exprt(op) : op);
1547+
guard.add(expr.id() == ID_or ? boolean_negate(op) : op);
15481548
}
15491549

15501550
guard = std::move(old_guard);
15511551
}
15521552

1553-
void goto_checkt::check_rec_if(const exprt &expr, guardt &guard)
1553+
void goto_checkt::check_rec_if(const if_exprt &if_expr, guardt &guard)
15541554
{
1555-
const if_exprt &if_expr = to_if_expr(expr);
1556-
15571555
INVARIANT(
15581556
if_expr.cond().is_boolean(),
15591557
"first argument of if must be boolean, but got " + if_expr.cond().pretty());
@@ -1575,9 +1573,8 @@ void goto_checkt::check_rec_if(const exprt &expr, guardt &guard)
15751573
}
15761574
}
15771575

1578-
void goto_checkt::check_rec_member(const exprt &expr, guardt &guard)
1576+
void goto_checkt::check_rec_member(const member_exprt &member, guardt &guard)
15791577
{
1580-
const member_exprt &member = to_member_expr(expr);
15811578
const dereference_exprt &deref = to_dereference_expr(member.struct_op());
15821579

15831580
check_rec(deref.pointer(), guard);
@@ -1594,7 +1591,7 @@ void goto_checkt::check_rec_member(const exprt &expr, guardt &guard)
15941591
if(member_offset_opt.has_value())
15951592
{
15961593
pointer_typet new_pointer_type = to_pointer_type(deref.pointer().type());
1597-
new_pointer_type.subtype() = expr.type();
1594+
new_pointer_type.subtype() = member.type();
15981595

15991596
const exprt char_pointer = typecast_exprt::conditional_cast(
16001597
deref.pointer(), pointer_type(char_type()));
@@ -1613,21 +1610,18 @@ void goto_checkt::check_rec_member(const exprt &expr, guardt &guard)
16131610

16141611
return;
16151612
}
1616-
1617-
for(const auto &operand : expr.operands())
1618-
check_rec(operand, guard);
16191613
}
16201614

1621-
void goto_checkt::check_rec_div(const exprt &expr, guardt &guard)
1615+
void goto_checkt::check_rec_div(const div_exprt &div_expr, guardt &guard)
16221616
{
1623-
div_by_zero_check(to_div_expr(expr), guard);
1617+
div_by_zero_check(to_div_expr(div_expr), guard);
16241618

1625-
if(expr.type().id() == ID_signedbv)
1626-
integer_overflow_check(expr, guard);
1627-
else if(expr.type().id() == ID_floatbv)
1619+
if(div_expr.type().id() == ID_signedbv)
1620+
integer_overflow_check(div_expr, guard);
1621+
else if(div_expr.type().id() == ID_floatbv)
16281622
{
1629-
nan_check(expr, guard);
1630-
float_overflow_check(expr, guard);
1623+
nan_check(div_expr, guard);
1624+
float_overflow_check(div_expr, guard);
16311625
}
16321626
}
16331627

@@ -1666,15 +1660,14 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard)
16661660
}
16671661
else if(expr.id() == ID_if)
16681662
{
1669-
check_rec_if(expr, guard);
1663+
check_rec_if(to_if_expr(expr), guard);
16701664
return;
16711665
}
16721666
else if(
16731667
expr.id() == ID_member &&
16741668
to_member_expr(expr).struct_op().id() == ID_dereference)
16751669
{
1676-
check_rec_member(expr, guard);
1677-
return;
1670+
check_rec_member(to_member_expr(expr), guard);
16781671
}
16791672

16801673
forall_operands(it, expr)
@@ -1686,7 +1679,7 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard)
16861679
}
16871680
else if(expr.id()==ID_div)
16881681
{
1689-
check_rec_div(expr, guard);
1682+
check_rec_div(to_div_expr(expr), guard);
16901683
}
16911684
else if(expr.id()==ID_shl || expr.id()==ID_ashr || expr.id()==ID_lshr)
16921685
{
@@ -1808,15 +1801,10 @@ void goto_checkt::goto_check(
18081801
{
18091802
if(std::find(i.labels.begin(), i.labels.end(), label)!=i.labels.end())
18101803
{
1811-
goto_program_instruction_typet type=
1812-
enable_assert_to_assume?ASSUME:ASSERT;
1813-
1814-
goto_programt::targett t = new_code.add(goto_programt::instructiont(
1815-
static_cast<const codet &>(get_nil_irep()),
1816-
i.source_location,
1817-
type,
1818-
false_exprt(),
1819-
{}));
1804+
auto t = new_code.add(
1805+
enable_assert_to_assume
1806+
? goto_programt::make_assumption(false_exprt{}, i.source_location)
1807+
: goto_programt::make_assertion(false_exprt{}, i.source_location));
18201808

18211809
t->source_location.set_property_class("error label");
18221810
t->source_location.set_comment("error label "+label);

0 commit comments

Comments
 (0)