@@ -1242,3 +1242,39 @@ TEST_CASE(
12421242 CHECK (converted == expected);
12431243 }
12441244}
1245+
1246+ TEST_CASE (" pointer_offset_exprt to SMT conversion" , " [core][smt2_incremental]" )
1247+ {
1248+ // The config lines are necessary to ensure that pointer width in configured.
1249+ config.ansi_c .mode = configt::ansi_ct::flavourt::GCC;
1250+ config.ansi_c .set_arch_spec_x86_64 ();
1251+ config.bv_encoding .object_bits = 8 ;
1252+
1253+ const auto pointer_type = pointer_typet (unsigned_int_type (), 64 /* bits */ );
1254+ const pointer_offset_exprt pointer_offset{
1255+ symbol_exprt{" foo" , pointer_type}, pointer_type};
1256+
1257+ SECTION (" simple pointer_offset_exprt conversion" )
1258+ {
1259+ const auto converted = convert_expr_to_smt (pointer_offset);
1260+ const auto expected =
1261+ smt_bit_vector_theoryt::zero_extend (8 )(smt_bit_vector_theoryt::extract (
1262+ 55 , 0 )(smt_identifier_termt (" foo" , smt_bit_vector_sortt (64 ))));
1263+ CHECK (converted == expected);
1264+ }
1265+
1266+ SECTION (" Invariant checks" )
1267+ {
1268+ const cbmc_invariants_should_throwt invariants_throw;
1269+ SECTION (" pointer_offset_exprt's operand type should be a bitvector type" )
1270+ {
1271+ auto pointer_offset_copy = pointer_offset;
1272+ pointer_offset_copy.type () = bool_typet{};
1273+ REQUIRE_THROWS_MATCHES (
1274+ convert_expr_to_smt (pointer_offset_copy),
1275+ invariant_failedt,
1276+ invariant_failure_containing (
1277+ " Pointer offset should have a bitvector-based type." ));
1278+ }
1279+ }
1280+ }
0 commit comments