-
Notifications
You must be signed in to change notification settings - Fork 274
New SMT2 backend: arithmetic operators implementation for fixed size bit vectors #6614
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
New SMT2 backend: arithmetic operators implementation for fixed size bit vectors #6614
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #6614 +/- ##
===========================================
+ Coverage 76.65% 76.72% +0.07%
===========================================
Files 1580 1579 -1
Lines 181560 181935 +375
===========================================
+ Hits 139168 139584 +416
+ Misses 42392 42351 -41
Continue to review full report at Codecov.
|
1b243b5
to
544f963
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. It would be nice to have unit tests of the validation of bitvector width being the same for the binary operations to ensure this is properly caught.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This an initial review of the first two commits titled - "Change order of casting and dispatching of binary_relation_exprt in convert_expr_to_smt
" and "Add implementation of arithmetic operator bvadd." only, so that I can leave some initial comments. My review of the remaining commits is still to follow.
REQUIRE(function_application.arguments().size() == 2); | ||
REQUIRE(function_application.arguments()[0].get() == two); | ||
REQUIRE(function_application.arguments()[1].get() == three); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ We should test that calling smt_bit_vector_theoryt::add
with bit_vectors of mismatched width or on bool sorted terms fails an invariant.
@@ -325,8 +325,12 @@ convert_expr_to_smt(const binary_relation_exprt &binary_relation) | |||
|
|||
static smt_termt convert_expr_to_smt(const plus_exprt &plus) | |||
{ | |||
UNIMPLEMENTED_FEATURE( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ I would prefer it if commits could be titled such that the title encompasses the entirety of what they change. The fact that you effectively have "Also add conversion of plus_exprt
to smt_bit_vector_theoryt::addition
" in the message body is kind of a red flag which suggests that you have combined unrelated changes together (even if one change depends of the other).
REQUIRE(function_application.get_sort() == smt_bit_vector_sortt{8}); | ||
REQUIRE(function_application.arguments().size() == 2); | ||
REQUIRE(function_application.arguments()[0].get() == two); | ||
REQUIRE(function_application.arguments()[1].get() == three); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ Tests for invariant violation on constructing with an lhs
and rhs
of mismatched widths and terms of bool sort please.
@@ -352,9 +360,11 @@ static smt_termt convert_expr_to_smt(const ieee_float_op_exprt &float_operation) | |||
|
|||
static smt_termt convert_expr_to_smt(const mod_exprt &truncation_modulo) | |||
{ | |||
UNIMPLEMENTED_FEATURE( | |||
"Generation of SMT formula for truncation modulo expression: " + | |||
truncation_modulo.pretty()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ We expect this operator to be applied only to (signed/unsigned) integer bit vectors. It might be good to document this expectation using a UNEXPECTEDCASE
macro, similar to how smt2_convt::convert_mod
does this.
544f963
to
9bbae2c
Compare
9bbae2c
to
4582586
Compare
a31b70a
to
4482566
Compare
4482566
to
bdbb900
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am now approving as all of my 🚫 comments have been addressed.
@@ -366,10 +366,22 @@ static smt_termt convert_expr_to_smt(const div_exprt ÷) | |||
can_cast_type<integer_bitvector_typet>(divide.lhs().type()) && | |||
can_cast_type<integer_bitvector_typet>(divide.rhs().type()); | |||
|
|||
bool both_operands_unsigned = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ const
- Every variable which is not mutated should be declared const
. I have picked this as an arbitrary example, but I think it is missing in a few places.
else | ||
{ | ||
return smt_bit_vector_theoryt::signed_divide( | ||
convert_expr_to_smt(divide.lhs()), convert_expr_to_smt(divide.rhs())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 I suggest introducing lhs_term
and rhs_term
variables above this if statement, so that the calls to convert_expr_to_smt
are not duplicated in the two branches.
{ | ||
return smt_bit_vector_theoryt::signed_remainder( | ||
convert_expr_to_smt(truncation_modulo.lhs()), | ||
convert_expr_to_smt(truncation_modulo.rhs())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Factor out the common convert_expr_to_smt
sub-expressions, like I suggested with your implementation for the divide operations.
bdbb900
to
8a75cd7
Compare
Also add tests for the data structure itself and the conversion of `plus_exprt` to `smt_bit_vector_theoryt::addition`.
8a75cd7
to
407f30c
Compare
Also add tests for it, both the conversion of `minus_exprt` to it, and the node factory constructing the nodes appropriately.
Also add tests for its conversion from `mult_exprt` and of the factory integrity.
Along with tests of its conversion and the function application factory integrity.
In addition, modify the tests and the implementation of the conversion function to account for signed/unsigned input.
Along with tests of its conversion and the function application factory integrity.
Along with this, change the tests and implementation of the conversion function to account for signed/unsigned inputs.
Along with conversion tests and tests of the factory method integrity.
…tor_operator_arguments`. This allows the name to reflect the more general purpose deployment of this function.
407f30c
to
b11a3b2
Compare
This adds implementations (and tests) for the binary arithmetic operators (and their conversion) to SMT2 data structures.