Skip to content

Commit 5289c58

Browse files
committed
Address review comments
Will be squashed.
1 parent 213d38f commit 5289c58

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

src/analyses/goto_check.cpp

+26-34
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,26 @@ class goto_checkt
111111
/// Check an if expression: check the if-condition alone, and then check the
112112
/// true/false-cases with the guard extended with if-condition and it's
113113
/// negation, respectively.
114-
/// \param expr: the expression to be checked
114+
/// \param if_expr: the expression to be checked
115115
/// \param guard: the condition for the check (extended with the (negation of
116116
/// the) if-condition for recursively calls)
117-
void check_rec_if(const exprt &expr, guardt &guard);
117+
void check_rec_if(const if_exprt &if_expr, guardt &guard);
118118

119119
/// Check that a member expression is valid:
120120
/// - check the structure this expression is a member of (via pointer of its
121121
/// dereference)
122122
/// - run pointer-validity check on `*(s+member_offset)' instead of
123123
/// `s->member' to avoid checking safety of `s'
124124
/// - check all operands of the expression
125-
/// \param expr: the expression to be checked
125+
/// \param member: the expression to be checked
126126
/// \param guard: the condition for the check (unmodified here)
127-
void check_rec_member(const exprt &expr, guardt &guard);
127+
void check_rec_member(const member_exprt &member, guardt &guard);
128128

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

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

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

15471547
check_rec(op, guard);
1548-
guard.add(expr.id() == ID_or ? not_exprt(op) : op);
1548+
guard.add(expr.id() == ID_or ? boolean_negate(op) : op);
15491549
}
15501550

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

1554-
void goto_checkt::check_rec_if(const exprt &expr, guardt &guard)
1554+
void goto_checkt::check_rec_if(const if_exprt &if_expr, guardt &guard)
15551555
{
1556-
const if_exprt &if_expr = to_if_expr(expr);
1557-
15581556
INVARIANT(
15591557
if_expr.cond().is_boolean(),
15601558
"first argument of if must be boolean, but got " + if_expr.cond().pretty());
@@ -1576,9 +1574,8 @@ void goto_checkt::check_rec_if(const exprt &expr, guardt &guard)
15761574
}
15771575
}
15781576

1579-
void goto_checkt::check_rec_member(const exprt &expr, guardt &guard)
1577+
void goto_checkt::check_rec_member(const member_exprt &member, guardt &guard)
15801578
{
1581-
const member_exprt &member = to_member_expr(expr);
15821579
const dereference_exprt &deref = to_dereference_expr(member.struct_op());
15831580

15841581
check_rec(deref.pointer(), guard);
@@ -1595,7 +1592,7 @@ void goto_checkt::check_rec_member(const exprt &expr, guardt &guard)
15951592
if(member_offset_opt.has_value())
15961593
{
15971594
pointer_typet new_pointer_type = to_pointer_type(deref.pointer().type());
1598-
new_pointer_type.subtype() = expr.type();
1595+
new_pointer_type.subtype() = member.type();
15991596

16001597
const exprt char_pointer = typecast_exprt::conditional_cast(
16011598
deref.pointer(), pointer_type(char_type()));
@@ -1615,20 +1612,20 @@ void goto_checkt::check_rec_member(const exprt &expr, guardt &guard)
16151612
return;
16161613
}
16171614

1618-
for(const auto &operand : expr.operands())
1615+
for(const auto &operand : member.operands())
16191616
check_rec(operand, guard);
16201617
}
16211618

1622-
void goto_checkt::check_rec_div(const exprt &expr, guardt &guard)
1619+
void goto_checkt::check_rec_div(const div_exprt &div_expr, guardt &guard)
16231620
{
1624-
div_by_zero_check(to_div_expr(expr), guard);
1621+
div_by_zero_check(to_div_expr(div_expr), guard);
16251622

1626-
if(expr.type().id() == ID_signedbv)
1627-
integer_overflow_check(expr, guard);
1628-
else if(expr.type().id() == ID_floatbv)
1623+
if(div_expr.type().id() == ID_signedbv)
1624+
integer_overflow_check(div_expr, guard);
1625+
else if(div_expr.type().id() == ID_floatbv)
16291626
{
1630-
nan_check(expr, guard);
1631-
float_overflow_check(expr, guard);
1627+
nan_check(div_expr, guard);
1628+
float_overflow_check(div_expr, guard);
16321629
}
16331630
}
16341631

@@ -1667,14 +1664,14 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard)
16671664
}
16681665
else if(expr.id() == ID_if)
16691666
{
1670-
check_rec_if(expr, guard);
1667+
check_rec_if(to_if_expr(expr), guard);
16711668
return;
16721669
}
16731670
else if(
16741671
expr.id() == ID_member &&
16751672
to_member_expr(expr).struct_op().id() == ID_dereference)
16761673
{
1677-
check_rec_member(expr, guard);
1674+
check_rec_member(to_member_expr(expr), guard);
16781675
return;
16791676
}
16801677

@@ -1687,7 +1684,7 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard)
16871684
}
16881685
else if(expr.id()==ID_div)
16891686
{
1690-
check_rec_div(expr, guard);
1687+
check_rec_div(to_div_expr(expr), guard);
16911688
}
16921689
else if(expr.id()==ID_shl || expr.id()==ID_ashr || expr.id()==ID_lshr)
16931690
{
@@ -1867,15 +1864,10 @@ void goto_checkt::goto_check(
18671864
{
18681865
if(std::find(i.labels.begin(), i.labels.end(), label)!=i.labels.end())
18691866
{
1870-
goto_program_instruction_typet type=
1871-
enable_assert_to_assume?ASSUME:ASSERT;
1872-
1873-
goto_programt::targett t = new_code.add(goto_programt::instructiont(
1874-
static_cast<const codet &>(get_nil_irep()),
1875-
i.source_location,
1876-
type,
1877-
false_exprt(),
1878-
{}));
1867+
auto t = new_code.add(
1868+
enable_assert_to_assume
1869+
? goto_programt::make_assumption(false_exprt{}, i.source_location)
1870+
: goto_programt::make_assertion(false_exprt{}, i.source_location));
18791871

18801872
t->source_location.set_property_class("error label");
18811873
t->source_location.set_comment("error label "+label);

0 commit comments

Comments
 (0)