Skip to content

Refactor boolbvt::convert_overflow #6752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 9 additions & 3 deletions src/solvers/flattening/boolbv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,16 @@ literalt boolbvt::convert_rest(const exprt &expr)
else if(expr.id()==ID_onehot || expr.id()==ID_onehot0)
return convert_onehot(to_unary_expr(expr));
else if(
can_cast_expr<binary_overflow_exprt>(expr) ||
can_cast_expr<unary_minus_overflow_exprt>(expr))
const auto binary_overflow =
expr_try_dynamic_cast<binary_overflow_exprt>(expr))
{
return convert_overflow(expr);
return convert_binary_overflow(*binary_overflow);
}
else if(
const auto unary_overflow =
expr_try_dynamic_cast<unary_overflow_exprt>(expr))
{
return convert_unary_overflow(*unary_overflow);
}
else if(expr.id()==ID_isnan)
{
Expand Down
5 changes: 4 additions & 1 deletion src/solvers/flattening/boolbv.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Author: Daniel Kroening, [email protected]
#include "arrays.h"

class array_comprehension_exprt;
class binary_overflow_exprt;
class bitreverse_exprt;
class bswap_exprt;
class byte_extract_exprt;
Expand All @@ -38,6 +39,7 @@ class floatbv_typecast_exprt;
class ieee_float_op_exprt;
class member_exprt;
class replication_exprt;
class unary_overflow_exprt;
class union_typet;

class boolbvt:public arrayst
Expand Down Expand Up @@ -140,7 +142,8 @@ class boolbvt:public arrayst
virtual literalt convert_reduction(const unary_exprt &expr);
virtual literalt convert_onehot(const unary_exprt &expr);
virtual literalt convert_extractbit(const extractbit_exprt &expr);
virtual literalt convert_overflow(const exprt &expr);
virtual literalt convert_binary_overflow(const binary_overflow_exprt &expr);
virtual literalt convert_unary_overflow(const unary_overflow_exprt &expr);
virtual literalt convert_equality(const equal_exprt &expr);
virtual literalt convert_verilog_case_equality(
const binary_relation_exprt &expr);
Expand Down
10 changes: 8 additions & 2 deletions src/solvers/flattening/boolbv_overflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Author: Daniel Kroening, [email protected]

#include "boolbv.h"

literalt boolbvt::convert_overflow(const exprt &expr)
literalt boolbvt::convert_binary_overflow(const binary_overflow_exprt &expr)
{
const auto plus_or_minus_conversion =
[&](
Expand Down Expand Up @@ -161,7 +161,13 @@ literalt boolbvt::convert_overflow(const exprt &expr)
return
prop.land(!neg_shift, prop.lselect(undef, prop.lor(bv0), overflow));
}
else if(

return SUB::convert_rest(expr);
}

literalt boolbvt::convert_unary_overflow(const unary_overflow_exprt &expr)
{
if(
Comment on lines +154 to +156
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There really is just this single unary_minus_overflow_exprt that exists for this case, so I would suggest to make this convert_unary_minus_overflow(const unary_minus_overflow_exprt &expr).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unary_minus_overflow_exprt and unary_overflow_exprt are currently equivalent. This fact could be used to simplify the way they are currently used, or even to remove unary_overflow_exprt and just keep unary_minus_overflow_exprt. However I think it would make it more difficult to add other kinds of unary overflow expressions. Adding more checks isn't something I am planning to work on but does seem worth considering. The following example unary operations might be considered for overflow checks -

  • The existing abs_exprt.
  • Increment operators ++ / --.
  • The trigonometric tan / "tangent" operation.
  • Could a narrowing cast be considered to overflow?

const auto unary_minus_overflow =
expr_try_dynamic_cast<unary_minus_overflow_exprt>(expr))
{
Expand Down