Skip to content

Commit 5cdccdd

Browse files
committed
Add getting of pointer values in new SMT2 decision procedure
1 parent a5ce4e5 commit 5cdccdd

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/solvers/smt2_incremental/construct_value_expr_from_smt.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Author: Diffblue Ltd.
22

3-
#include <solvers/smt2_incremental/construct_value_expr_from_smt.h>
4-
5-
#include <solvers/smt2_incremental/smt_terms.h>
6-
73
#include <util/arith_tools.h>
84
#include <util/bitvector_types.h>
5+
#include <util/pointer_expr.h>
96
#include <util/std_expr.h>
107
#include <util/std_types.h>
118
#include <util/type.h>
129

10+
#include <solvers/smt2_incremental/construct_value_expr_from_smt.h>
11+
#include <solvers/smt2_incremental/smt_terms.h>
12+
1313
class value_expr_from_smt_factoryt : public smt_term_const_downcast_visitort
1414
{
1515
private:
@@ -37,13 +37,35 @@ class value_expr_from_smt_factoryt : public smt_term_const_downcast_visitort
3737

3838
void visit(const smt_bit_vector_constant_termt &bit_vector_constant) override
3939
{
40+
const auto sort_width = bit_vector_constant.get_sort().bit_width();
41+
if(
42+
const auto pointer_type =
43+
type_try_dynamic_cast<pointer_typet>(type_to_construct))
44+
{
45+
INVARIANT(
46+
pointer_type->get_width() == sort_width,
47+
"Width of smt bit vector term must match the width of pointer type.");
48+
if(bit_vector_constant.value() == 0)
49+
{
50+
result = null_pointer_exprt{*pointer_type};
51+
}
52+
else
53+
{
54+
// The reason we are manually constructing a constant_exprt here is a
55+
// limitation in the design of `from_integer`, which only allows it to
56+
// be used with pointer values of 0 (null pointers).
57+
result = constant_exprt{
58+
integer2bvrep(bit_vector_constant.value(), sort_width),
59+
*pointer_type};
60+
}
61+
return;
62+
}
4063
if(
4164
const auto bitvector_type =
4265
type_try_dynamic_cast<bitvector_typet>(type_to_construct))
4366
{
4467
INVARIANT(
45-
bitvector_type->get_width() ==
46-
bit_vector_constant.get_sort().bit_width(),
68+
bitvector_type->get_width() == sort_width,
4769
"Width of smt bit vector term must match the width of bit vector "
4870
"type.");
4971
result = from_integer(bit_vector_constant.value(), type_to_construct);

0 commit comments

Comments
 (0)