|
8 | 8 | #include <util/constructor_of.h>
|
9 | 9 | #include <util/format.h>
|
10 | 10 | #include <util/namespace.h>
|
| 11 | +#include <util/pointer_predicates.h> |
11 | 12 | #include <util/std_expr.h>
|
12 | 13 | #include <util/symbol_table.h>
|
13 | 14 |
|
@@ -1186,3 +1187,58 @@ TEST_CASE(
|
1186 | 1187 | smt_bit_vector_constant_termt{0, 56})));
|
1187 | 1188 | }
|
1188 | 1189 | }
|
| 1190 | + |
| 1191 | +TEST_CASE( |
| 1192 | + "expr to smt conversion for pointer object expression", |
| 1193 | + "[core][smt2_incremental]") |
| 1194 | +{ |
| 1195 | + // The config lines are necessary to ensure that pointer width in configured. |
| 1196 | + config.ansi_c.mode = configt::ansi_ct::flavourt::GCC; |
| 1197 | + config.ansi_c.set_arch_spec_x86_64(); |
| 1198 | + config.bv_encoding.object_bits = 8; |
| 1199 | + |
| 1200 | + const auto pointer_type = pointer_typet(unsigned_int_type(), 64 /* bits */); |
| 1201 | + const pointer_object_exprt foo{ |
| 1202 | + symbol_exprt{"foo", pointer_type}, pointer_type}; |
| 1203 | + const pointer_object_exprt foobar{ |
| 1204 | + symbol_exprt{"foobar", pointer_type}, pointer_type}; |
| 1205 | + |
| 1206 | + SECTION("Pointer object expression") |
| 1207 | + { |
| 1208 | + const auto converted = convert_expr_to_smt(foo); |
| 1209 | + const auto expected = |
| 1210 | + smt_bit_vector_theoryt::zero_extend(56)(smt_bit_vector_theoryt::extract( |
| 1211 | + 63, 56)(smt_identifier_termt("foo", smt_bit_vector_sortt(64)))); |
| 1212 | + CHECK(converted == expected); |
| 1213 | + } |
| 1214 | + |
| 1215 | + SECTION("Invariant checks") |
| 1216 | + { |
| 1217 | + const cbmc_invariants_should_throwt invariants_throw; |
| 1218 | + SECTION("Pointer object's operand type should be a bitvector type") |
| 1219 | + { |
| 1220 | + auto copy_of_foo = foo; |
| 1221 | + copy_of_foo.type() = bool_typet{}; |
| 1222 | + REQUIRE_THROWS_MATCHES( |
| 1223 | + convert_expr_to_smt(copy_of_foo), |
| 1224 | + invariant_failedt, |
| 1225 | + invariant_failure_containing( |
| 1226 | + "Pointer object should have a bitvector-based type.")); |
| 1227 | + } |
| 1228 | + } |
| 1229 | + |
| 1230 | + SECTION("Comparison of pointer objects.") |
| 1231 | + { |
| 1232 | + const exprt comparison = notequal_exprt{foobar, foo}; |
| 1233 | + INFO("Expression " + comparison.pretty(1, 0)); |
| 1234 | + const auto converted = convert_expr_to_smt(comparison); |
| 1235 | + const auto bv1 = |
| 1236 | + smt_bit_vector_theoryt::zero_extend(56)(smt_bit_vector_theoryt::extract( |
| 1237 | + 63, 56)(smt_identifier_termt("foo", smt_bit_vector_sortt(64)))); |
| 1238 | + const auto bv2 = |
| 1239 | + smt_bit_vector_theoryt::zero_extend(56)(smt_bit_vector_theoryt::extract( |
| 1240 | + 63, 56)(smt_identifier_termt("foobar", smt_bit_vector_sortt(64)))); |
| 1241 | + const auto expected = smt_core_theoryt::distinct(bv2, bv1); |
| 1242 | + CHECK(converted == expected); |
| 1243 | + } |
| 1244 | +} |
0 commit comments