Skip to content

fix accesses to exprt::opX() in solvers/ #5025

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 2 commits into from
Nov 7, 2019
Merged

fix accesses to exprt::opX() in solvers/ #5025

merged 2 commits into from
Nov 7, 2019

Conversation

kroening
Copy link
Member

This improves type safety.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • n/a My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 56cf656).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/123385109

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

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

Blocking for one breaking change, otherwise suggested optional improvements

DATA_INVARIANT(
a.operands().size()==1,
"typecast must have one operand");
const auto &typecast_op = to_typecast_expr(a);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd expect typecast_op to be to_typecast_expr(a).op(). Just typecast_expr?

a.op0().type().id()==ID_array,
("unexpected array type cast from "+
a.op0().type().id_string()).c_str());
typecast_op.type().id() == ID_array,
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you really did want typecast(...).op() above, this is a change of behaviour

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed -- fixed

expr.op0().type().id()==ID_floatbv)))
else if(
!use_FPA_theory && expr.operands().size() >= 1 &&
(expr.id() == ID_floatbv_plus || expr.id() == ID_floatbv_minus ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest clang-format-off, the old style was much easier to read

arg.op0().op0().operands().size() == 2 &&
arg.op0().op0().op0().id() == ID_string_constant)
arg.operands().size() == 1 &&
to_unary_expr(arg).op().operands().size() == 1 &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Any idea what this is expecting? The chain of op0s without checking what unary operation it's looking at seems suspicious

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's an equality whose lhs is an address_of string_constant -- @romainbrenguier ?

Copy link
Contributor

Choose a reason for hiding this comment

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

this could have been an address_of although I can't be sure now. This is most likely dead code, as this is for C programs, for which the solver is not tested currently, and wouldn't work without some clean-up.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 0b62e99).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/123438774

@codecov-io
Copy link

codecov-io commented Aug 15, 2019

Codecov Report

Merging #5025 into develop will increase coverage by <.01%.
The diff coverage is 73.15%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5025      +/-   ##
===========================================
+ Coverage    67.33%   67.33%   +<.01%     
===========================================
  Files         1155     1155              
  Lines        94669    94684      +15     
===========================================
+ Hits         63744    63755      +11     
- Misses       30925    30929       +4
Flag Coverage Δ
#cproversmt2 42.64% <38.91%> (-0.01%) ⬇️
#regression 63.82% <54.08%> (ø) ⬆️
#unit 31.97% <18.47%> (+0.01%) ⬆️
Impacted Files Coverage Δ
src/solvers/smt2/smt2_conv.h 100% <ø> (ø) ⬆️
src/solvers/flattening/boolbv.h 78.57% <ø> (ø) ⬆️
src/solvers/refinement/bv_refinement.h 100% <ø> (ø) ⬆️
...lvers/strings/string_constraint_generator_main.cpp 84% <0%> (-0.49%) ⬇️
src/solvers/qbf/qdimacs_core.cpp 0% <0%> (ø) ⬆️
src/solvers/flattening/boolbv_update.cpp 0% <0%> (ø) ⬆️
...olvers/flattening/boolbv_constraint_select_one.cpp 0% <0%> (ø) ⬆️
src/solvers/flattening/boolbv_add_sub.cpp 50% <100%> (+0.87%) ⬆️
src/solvers/flattening/boolbv_bitwise.cpp 90.32% <100%> (ø) ⬆️
src/solvers/flattening/boolbv_ieee_float_rel.cpp 86.66% <100%> (ø) ⬆️
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 001b6f9...8a6f9aa. Read the comment docs.

#else
literalt literal=bv_utils.rel(bv0, expr.id(), bv1, rep);
#else
literalt literal = bv_utils.rel(bv0, expr.id(), bv1, rep);
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this part of the code should be removed instead of reformatted

arg.op0().op0().operands().size() == 2 &&
arg.op0().op0().op0().id() == ID_string_constant)
arg.operands().size() == 1 &&
to_unary_expr(arg).op().operands().size() == 1 &&
Copy link
Contributor

Choose a reason for hiding this comment

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

this could have been an address_of although I can't be sure now. This is most likely dead code, as this is for C programs, for which the solver is not tested currently, and wouldn't work without some clean-up.

Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

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

There are a number of locations where lhs() and rhs() can be used to make the code clearer and to remove the number of calls to op0() and op1() making them easier to locate and eliminate.

DATA_INVARIANT(
a.operands().size()==1,
"typecast must have one operand");
const auto &typecast_op = to_typecast_expr(a).op();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a definite improvement.

@@ -201,7 +201,7 @@ bvt boolbvt::convert_bitvector(const exprt &expr)
if(expr.operands().size()!=1)
return conversion_failed(expr);

std::size_t op_width=boolbv_width(expr.op0().type());
std::size_t op_width = boolbv_width(to_unary_expr(expr).op().type());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure that width is a unary_exprt...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure there's anything wrong here?

@@ -41,7 +41,7 @@ bvt boolbvt::convert_add_sub(const exprt &expr)
!operands.empty(),
"operator " + expr.id_string() + " takes at least one operand");

const exprt &op0=expr.op0();
const exprt &op0 = to_multi_ary_expr(expr).op0();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Still has an op0 but probably unavoidable.


if(operands.size()!=3)
throw "operator "+expr.id_string()+" takes three operands";

const exprt &lhs = expr.op0();
Copy link
Collaborator

Choose a reason for hiding this comment

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

For completeness and to make it easier to find remaining uses, these could be lhs(), rhs() and rounding_mode().

Copy link
Member Author

Choose a reason for hiding this comment

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

done

{
const auto &float_expr = to_ieee_float_op_expr(expr);
return div(
float_expr.op0(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

As above.

bddt op0 = from_expr_rec(bin_expr.op0());
bddt op1 = from_expr_rec(bin_expr.op1());
bddt op0 = from_expr_rec(to_binary_expr(bin_expr).op0());
bddt op1 = from_expr_rec(to_binary_expr(bin_expr).op1());
Copy link
Collaborator

Choose a reason for hiding this comment

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

lhs() and rhs()

return;
}
const auto &implies_expr = to_implies_expr(expr);
literalt l0 = convert(implies_expr.op0());
Copy link
Collaborator

Choose a reason for hiding this comment

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

lhs() and rhs()

Copy link
Member Author

Choose a reason for hiding this comment

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

Same as above -- will do a PR for a binary_infix_exprt.

kroening pushed a commit that referenced this pull request Aug 21, 2019
This is follow up from #5025.  A clear desire is visible to use .lhs() and
.rhs() on binary expressions, say minus_exprt.
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 0d4e7b7).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/124103489

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 47099cd).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/128738923

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 7342799).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/131366463

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: c29fcd8).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/131640304

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 0a3c6a5).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/132766120

@@ -201,7 +201,7 @@ bvt boolbvt::convert_bitvector(const exprt &expr)
if(expr.operands().size()!=1)
return conversion_failed(expr);

std::size_t op_width=boolbv_width(expr.op0().type());
std::size_t op_width = boolbv_width(to_unary_expr(expr).op().type());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure there's anything wrong here?

DATA_INVARIANT(expr.operands().size() == 1, "isnan expects one operand");
const bvt &bv=convert_bv(operands[0]);
const auto &op = to_unary_expr(expr).op();
const bvt &bv = convert_bv(op);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems the original code had operands declared somewhere. In the code review it's hard to see where that is, but can you please make sure its declaration is removed as it shouldn't be of any use anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, removed

bv_utilst::representationt rep=
expr.op0().type().id()==ID_signedbv?bv_utilst::representationt::SIGNED:
bv_utilst::representationt::UNSIGNED;
bv_utilst::representationt rep = operands[0].type().id() == ID_signedbv
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure the use of operands[0] is an improvement?

Copy link
Member Author

Choose a reason for hiding this comment

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

replaced by binary_exprt

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 8a6f9aa).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/135115290

Daniel Kroening added 2 commits November 7, 2019 16:29
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: dbf0058).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/135506038

@kroening kroening merged commit ee79ae2 into develop Nov 7, 2019
@kroening kroening deleted the solvers-opX branch November 7, 2019 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants