Skip to content

Commit 4563e0e

Browse files
committed
Add conversion of object_size expressions
1 parent 4a859f3 commit 4563e0e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,11 +1238,18 @@ static smt_termt convert_expr_to_smt(
12381238

12391239
static smt_termt convert_expr_to_smt(
12401240
const object_size_exprt &object_size,
1241-
const sub_expression_mapt &converted)
1241+
const sub_expression_mapt &converted,
1242+
const smt_object_sizet::make_applicationt &call_object_size)
12421243
{
1243-
UNIMPLEMENTED_FEATURE(
1244-
"Generation of SMT formula for object_size expression: " +
1245-
object_size.pretty());
1244+
const smt_termt &pointer = converted.at(object_size.pointer());
1245+
const auto pointer_sort = pointer.get_sort().cast<smt_bit_vector_sortt>();
1246+
INVARIANT(
1247+
pointer_sort, "Pointers should be encoded as bit vector sorted terms.");
1248+
const std::size_t pointer_width = pointer_sort->bit_width();
1249+
return call_object_size(
1250+
std::vector<smt_termt>{smt_bit_vector_theoryt::extract(
1251+
pointer_width - 1,
1252+
pointer_width - config.bv_encoding.object_bits)(pointer)});
12461253
}
12471254

12481255
static smt_termt
@@ -1292,7 +1299,7 @@ static smt_termt dispatch_expr_to_smt_conversion(
12921299
const exprt &expr,
12931300
const sub_expression_mapt &converted,
12941301
const smt_object_mapt &object_map,
1295-
const smt_object_sizet::make_applicationt &object_size)
1302+
const smt_object_sizet::make_applicationt &call_object_size)
12961303
{
12971304
if(const auto symbol = expr_try_dynamic_cast<symbol_exprt>(expr))
12981305
{
@@ -1590,7 +1597,7 @@ static smt_termt dispatch_expr_to_smt_conversion(
15901597
}
15911598
if(const auto object_size = expr_try_dynamic_cast<object_size_exprt>(expr))
15921599
{
1593-
return convert_expr_to_smt(*object_size, converted);
1600+
return convert_expr_to_smt(*object_size, converted, call_object_size);
15941601
}
15951602
if(const auto let = expr_try_dynamic_cast<let_exprt>(expr))
15961603
{

unit/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ TEST_CASE("\"typet\" to smt sort conversion", "[core][smt2_incremental]")
4545

4646
smt_termt convert_expr_to_smt(const exprt &expression)
4747
{
48+
// These config lines are necessary before conversion because pointer
49+
// widths and object bit width encodings depend on the global configuration.
50+
config.ansi_c.mode = configt::ansi_ct::flavourt::GCC;
51+
config.ansi_c.set_arch_spec_i386();
4852
return convert_expr_to_smt(
4953
expression, initial_smt_object_map(), smt_object_sizet{}.make_application);
5054
}

0 commit comments

Comments
 (0)