Skip to content

Commit 6f42b0e

Browse files
committed
re-encode integers converted to pointers
1 parent b08c997 commit 6f42b0e

File tree

7 files changed

+22
-15
lines changed

7 files changed

+22
-15
lines changed

regression/cbmc-library/fprintf-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-primitives/r_w_ok_inconsistent_invalid/test-no-cp.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-check --no-simplify --no-propagation
44
^EXIT=0$

regression/cbmc-primitives/r_w_ok_inconsistent_invalid/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-check
44
^EXIT=0$

regression/cbmc/memory_allocation1/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG broken-smt-backend
1+
CORE broken-smt-backend
22
main.c
33
--pointer-check
44
^EXIT=10$

regression/cbmc/mm_io1/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33

44
^EXIT=0$

regression/cbmc/pointer-extra-checks/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-check
44
^EXIT=10$

src/solvers/flattening/bv_pointers.cpp

+16-9
Original file line numberDiff line numberDiff line change
@@ -76,29 +76,29 @@ bvt bv_pointerst::object_literals(const bvt &bv, const pointer_typet &type)
7676
PRECONDITION(width == bv.size());
7777

7878
const auto result = prop.new_variables(width);
79-
bvt match_found;
79+
bvt match_found_disjuncts;
8080

8181
for(std::size_t i = 0; i < numbered_pointers.size(); i++)
8282
{
8383
auto cond = bv_utils.equal(
8484
bv,
8585
bv_utilst::concatenate(
8686
bv_utilst::build_constant(i, width - 1), {const_literal(true)}));
87-
match_found.push_back(cond);
87+
match_found_disjuncts.push_back(cond);
8888
bv_utils.cond_implies_equal(
8989
cond,
9090
bv_utilst::zero_extension(numbered_pointers[i].first, width),
9191
result);
9292
}
9393

94-
auto within_bounds = prop.lor(match_found);
94+
auto match_found = prop.lor(match_found_disjuncts);
9595

9696
// The top bit distinguishes 'object only' vs. 'table encoded'.
9797
// When outside of the table, return an invalid object.
9898
return bv_utils.select(
9999
bv.back(),
100100
bv_utils.select(
101-
within_bounds,
101+
match_found,
102102
result,
103103
bv_utilst::build_constant(pointer_logic.get_invalid_object(), width)),
104104
bv);
@@ -110,21 +110,28 @@ bvt bv_pointerst::offset_literals(const bvt &bv, const pointer_typet &type)
110110
PRECONDITION(width == bv.size());
111111

112112
const auto result = prop.new_variables(width);
113+
bvt match_found_disjuncts;
113114

114115
for(std::size_t i = 0; i < numbered_pointers.size(); i++)
115116
{
116117
auto cond = bv_utils.equal(
117118
bv,
118119
bv_utilst::concatenate(
119120
bv_utilst::build_constant(i, width - 1), {const_literal(true)}));
121+
match_found_disjuncts.push_back(cond);
120122
bv_utils.cond_implies_equal(
121123
cond,
122124
bv_utilst::sign_extension(numbered_pointers[i].second, width),
123125
result);
124126
}
125127

128+
auto match_found = prop.lor(match_found_disjuncts);
129+
126130
// the top bit distinguishes 'object only' vs. 'table encoded'
127-
return bv_utils.select(bv.back(), result, bv_utilst::zeros(width));
131+
return bv_utils.select(
132+
bv.back(),
133+
bv_utils.select(match_found, result, bv_utilst::zeros(width)),
134+
bv_utilst::zeros(width));
128135
}
129136

130137
bvt bv_pointerst::object_offset_encoding(
@@ -436,11 +443,11 @@ bvt bv_pointerst::convert_pointer_type(const exprt &expr)
436443
op_type.id() == ID_c_enum || op_type.id() == ID_c_enum_tag)
437444
{
438445
// Cast from a bitvector type to pointer.
439-
// We just do a zero extension.
440-
446+
// We interpret as NULL + offset, where the offset is
447+
// derived from the bitvector by zero extension.
441448
const bvt &op_bv=convert_bv(op);
442-
443-
return bv_utils.zero_extension(op_bv, bits);
449+
return object_offset_encoding(
450+
bv_utilst::zeros(bits), bv_utilst::zero_extension(op_bv, bits), type);
444451
}
445452
}
446453
else if(expr.id()==ID_if)

0 commit comments

Comments
 (0)