Skip to content

Commit 15423e3

Browse files
committed
Add conversion of pointer_object_exprt and a regression test for that.
1 parent 074d3be commit 15423e3

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
int main()
2+
{
3+
int a = 10;
4+
int nondet_bool;
5+
int flag = 1;
6+
7+
int *b = &a;
8+
int *c = nondet_bool ? &a : 0;
9+
int *d = flag ? &a : 0;
10+
int *e;
11+
12+
// __CPROVER_same_object is True when
13+
// `__CPROVER_pointer_object(a) == __CPROVER_pointer_object(b)`
14+
__CPROVER_assert(
15+
__CPROVER_same_object(b, c), "expected fail as c can be null");
16+
__CPROVER_assert(
17+
__CPROVER_same_object(b, d), "expected success because d is &a");
18+
__CPROVER_assert(
19+
__CPROVER_same_object(b, e), "expected fail as e can be null");
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
pointer_object.c
3+
--trace --verbosity 10
4+
\[main\.assertion\.1\] line \d+ expected fail as c can be null: FAILURE
5+
\[main\.assertion\.2\] line \d+ expected success because d is &a: SUCCESS
6+
\[main\.assertion\.3\] line \d+ expected fail as e can be null: FAILURE
7+
^EXIT=10$
8+
^SIGNAL=0$
9+
--
10+
--

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,29 @@ static smt_termt convert_expr_to_smt(
11421142
mult_overflow.pretty());
11431143
}
11441144

1145+
static smt_termt convert_expr_to_smt(
1146+
const pointer_object_exprt &pointer_object,
1147+
const sub_expression_mapt &converted)
1148+
{
1149+
const auto type =
1150+
type_try_dynamic_cast<bitvector_typet>(pointer_object.type());
1151+
INVARIANT(type, "Pointer object should have a bitvector-based type.");
1152+
const auto converted_expr = converted.at(pointer_object.pointer());
1153+
const std::size_t width = type->get_width();
1154+
const std::size_t object_bits = config.bv_encoding.object_bits;
1155+
INVARIANT(
1156+
width >= object_bits,
1157+
"Width should be at least as big as the number of object bits.");
1158+
const std::size_t ext = width - object_bits;
1159+
const auto extract_op = smt_bit_vector_theoryt::extract(
1160+
width - 1, width - object_bits)(converted_expr);
1161+
if(ext > 0)
1162+
{
1163+
return smt_bit_vector_theoryt::zero_extend(ext)(extract_op);
1164+
}
1165+
return extract_op;
1166+
}
1167+
11451168
static smt_termt convert_expr_to_smt(
11461169
const shl_overflow_exprt &shl_overflow,
11471170
const sub_expression_mapt &converted)
@@ -1437,10 +1460,13 @@ static smt_termt dispatch_expr_to_smt_conversion(
14371460
else if(expr.id()==ID_pointer_offset)
14381461
{
14391462
}
1440-
else if(expr.id()==ID_pointer_object)
1463+
#endif
1464+
else if(
1465+
const auto pointer_object =
1466+
expr_try_dynamic_cast<pointer_object_exprt>(expr))
14411467
{
1468+
return convert_expr_to_smt(*pointer_object, converted);
14421469
}
1443-
#endif
14441470
if(
14451471
const auto is_dynamic_object =
14461472
expr_try_dynamic_cast<is_dynamic_object_exprt>(expr))

0 commit comments

Comments
 (0)