File tree 5 files changed +71
-3
lines changed
src/solvers/smt2_incremental
unit/solvers/smt2_incremental 5 files changed +71
-3
lines changed Original file line number Diff line number Diff line change @@ -380,9 +380,11 @@ static smt_termt convert_expr_to_smt(const ieee_float_op_exprt &float_operation)
380
380
381
381
static smt_termt convert_expr_to_smt (const mod_exprt &truncation_modulo)
382
382
{
383
- UNIMPLEMENTED_FEATURE (
384
- " Generation of SMT formula for truncation modulo expression: " +
385
- truncation_modulo.pretty ());
383
+ PRECONDITION (can_cast_type<bitvector_typet>(truncation_modulo.lhs ().type ()));
384
+ PRECONDITION (can_cast_type<bitvector_typet>(truncation_modulo.rhs ().type ()));
385
+ return smt_bit_vector_theoryt::remainder (
386
+ convert_expr_to_smt (truncation_modulo.lhs ()),
387
+ convert_expr_to_smt (truncation_modulo.rhs ()));
386
388
}
387
389
388
390
static smt_termt
Original file line number Diff line number Diff line change @@ -140,3 +140,29 @@ void smt_bit_vector_theoryt::divisiont::validate(
140
140
const smt_function_application_termt::factoryt<
141
141
smt_bit_vector_theoryt::divisiont>
142
142
smt_bit_vector_theoryt::division{};
143
+
144
+ const char *smt_bit_vector_theoryt::remaindert::identifier ()
145
+ {
146
+ return " bvurem" ;
147
+ }
148
+
149
+ smt_sortt smt_bit_vector_theoryt::remaindert::return_sort (
150
+ const smt_termt &lhs,
151
+ const smt_termt &rhs)
152
+ {
153
+ // For now, make sure that they have the same bit-width
154
+ remaindert::validate (lhs, rhs);
155
+ const auto width = lhs.get_sort ().cast <smt_bit_vector_sortt>()->bit_width ();
156
+ return smt_bit_vector_sortt{width};
157
+ }
158
+
159
+ void smt_bit_vector_theoryt::remaindert::validate (
160
+ const smt_termt &lhs,
161
+ const smt_termt &rhs)
162
+ {
163
+ validate_bit_vector_predicate_arguments (lhs, rhs);
164
+ }
165
+
166
+ const smt_function_application_termt::factoryt<
167
+ smt_bit_vector_theoryt::remaindert>
168
+ smt_bit_vector_theoryt::remainder{};
Original file line number Diff line number Diff line change @@ -53,6 +53,14 @@ class smt_bit_vector_theoryt
53
53
static void validate (const smt_termt &lhs, const smt_termt &rhs);
54
54
};
55
55
static const smt_function_application_termt::factoryt<divisiont> division;
56
+
57
+ struct remaindert final
58
+ {
59
+ static const char *identifier ();
60
+ static smt_sortt return_sort (const smt_termt &lhs, const smt_termt &rhs);
61
+ static void validate (const smt_termt &lhs, const smt_termt &rhs);
62
+ };
63
+ static const smt_function_application_termt::factoryt<remaindert> remainder;
56
64
};
57
65
58
66
#endif // CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT_BIT_VECTOR_THEORY_H
Original file line number Diff line number Diff line change @@ -357,4 +357,23 @@ TEST_CASE(
357
357
const cbmc_invariants_should_throwt invariants_throw;
358
358
REQUIRE_THROWS (convert_expr_to_smt (div_exprt{one_bvint, false_exprt{}}));
359
359
}
360
+
361
+ SECTION (
362
+ " Unsigned remainder (modulus) from truncating division of two constant "
363
+ " size bit-vectors" )
364
+ {
365
+ const auto constructed_term =
366
+ convert_expr_to_smt (mod_exprt{one_bvint_unsigned, two_bvint_unsigned});
367
+ const auto expected_term =
368
+ smt_bit_vector_theoryt::remainder (smt_term_one, smt_term_two);
369
+ CHECK (constructed_term == expected_term);
370
+ }
371
+
372
+ SECTION (
373
+ " Ensure that remainder (truncated modulo) node conversion fails if the "
374
+ " operands are not bit-vector based" )
375
+ {
376
+ const cbmc_invariants_should_throwt invariants_throw;
377
+ REQUIRE_THROWS (convert_expr_to_smt (mod_exprt{one_bvint, false_exprt{}}));
378
+ }
360
379
}
Original file line number Diff line number Diff line change @@ -238,4 +238,17 @@ TEST_CASE(
238
238
REQUIRE (function_application.arguments ()[0 ].get () == two);
239
239
REQUIRE (function_application.arguments ()[1 ].get () == three);
240
240
}
241
+
242
+ SECTION (" Remainder" )
243
+ {
244
+ const auto function_application =
245
+ smt_bit_vector_theoryt::remainder (two, three);
246
+ REQUIRE (
247
+ function_application.function_identifier () ==
248
+ smt_identifier_termt (" bvurem" , smt_bit_vector_sortt{8 }));
249
+ REQUIRE (function_application.get_sort () == smt_bit_vector_sortt{8 });
250
+ REQUIRE (function_application.arguments ().size () == 2 );
251
+ REQUIRE (function_application.arguments ()[0 ].get () == two);
252
+ REQUIRE (function_application.arguments ()[1 ].get () == three);
253
+ }
241
254
}
You can’t perform that action at this time.
0 commit comments