Skip to content

Commit 55509a5

Browse files
committed
Back-end support for {r,w,rw}_ok and pointer_in_range
There is no longer a need to rewrite these early on during program instrumentation. Instead, let the back-end handle them. For now, they are just handled by lowering the expressions (in the SAT and SMT back-end; there is no current support in the incremental SMT back-end just yet). We may, in future, decide to have back-end specific (and possibly more efficient) handling of these.
1 parent 8fc9b3f commit 55509a5

File tree

10 files changed

+62
-7
lines changed

10 files changed

+62
-7
lines changed

regression/cbmc-primitives/r_w_ok_bug/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE new-smt-backend
1+
CORE
22
main.c
33
--pointer-check --no-simplify --no-propagation
44
^\[main.pointer_dereference.\d+\] line 8 dereference failure: pointer outside object bounds in \*p1: FAILURE$

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE new-smt-backend
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE new-smt-backend
1+
CORE
22
main.c
33
--pointer-check
44
^EXIT=0$

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE new-smt-backend
1+
CORE
22
main.c
33
--pointer-check --no-simplify --no-propagation
44
^EXIT=0$

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE new-smt-backend
1+
CORE
22
main.c
33
--pointer-check --no-simplify --no-propagation
44
^EXIT=0$

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE new-smt-backend
1+
CORE
22
main.c
33
--pointer-check --no-simplify --no-propagation
44
^EXIT=0$

regression/cbmc-primitives/same-object-03/test-no-cp.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE new-smt-backend
1+
CORE
22
main.c
33
--no-simplify --no-propagation
44
^EXIT=0$

src/solvers/flattening/bv_pointers.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected]
1818
#include <util/pointer_expr.h>
1919
#include <util/pointer_offset_size.h>
2020
#include <util/pointer_predicates.h>
21+
#include <util/simplify_expr.h>
2122

2223
/// Map bytes according to the configured endianness. The key difference to
2324
/// endianness_mapt is that bv_endianness_mapt is aware of the bit-level
@@ -203,6 +204,10 @@ literalt bv_pointerst::convert_rest(const exprt &expr)
203204
bv_utilst::representationt::SIGNED));
204205
}
205206
}
207+
else if(expr.id() == ID_r_ok || expr.id() == ID_w_ok || expr.id() == ID_rw_ok)
208+
return convert(simplify_expr(to_r_or_w_ok_expr(expr).lower(ns), ns));
209+
else if(expr.id() == ID_pointer_in_range)
210+
return convert(simplify_expr(to_pointer_in_range_expr(expr).lower(ns), ns));
206211

207212
return SUB::convert_rest(expr);
208213
}

src/solvers/smt2/smt2_conv.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5010,6 +5010,28 @@ exprt smt2_convt::prepare_for_convert_expr(const exprt &expr)
50105010
!has_byte_operator(lowered_expr),
50115011
"lower_byte_operators should remove all byte operators");
50125012

5013+
// Perform rewrites that may introduce new symbols
5014+
for(auto it = lowered_expr.depth_begin(), itend = lowered_expr.depth_end();
5015+
it != itend;) // no ++it
5016+
{
5017+
if(auto r_or_w_ok = expr_try_dynamic_cast<r_or_w_ok_exprt>(*it))
5018+
{
5019+
exprt lowered = simplify_expr(r_or_w_ok->lower(ns), ns);
5020+
it.mutate() = lowered;
5021+
it.next_sibling_or_parent();
5022+
}
5023+
else if(
5024+
auto pointer_in_range =
5025+
expr_try_dynamic_cast<pointer_in_range_exprt>(*it))
5026+
{
5027+
exprt lowered = simplify_expr(pointer_in_range->lower(ns), ns);
5028+
it.mutate() = lowered;
5029+
it.next_sibling_or_parent();
5030+
}
5031+
else
5032+
++it;
5033+
}
5034+
50135035
// Now create symbols for all composite expressions present in lowered_expr:
50145036
find_symbols(lowered_expr);
50155037

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,24 @@ static smt_termt convert_expr_to_smt(
14661466
count_trailing_zeros.pretty());
14671467
}
14681468

1469+
static smt_termt convert_expr_to_smt(
1470+
const r_or_w_ok_exprt &r_or_w_ok,
1471+
const sub_expression_mapt &converted)
1472+
{
1473+
UNIMPLEMENTED_FEATURE(
1474+
"Generation of SMT formula for r/w/rw ok expression: " +
1475+
r_or_w_ok.pretty());
1476+
}
1477+
1478+
static smt_termt convert_expr_to_smt(
1479+
const pointer_in_range_exprt &pointer_in_range,
1480+
const sub_expression_mapt &converted)
1481+
{
1482+
UNIMPLEMENTED_FEATURE(
1483+
"Generation of SMT formula for pointer-in-range expression: " +
1484+
pointer_in_range.pretty());
1485+
}
1486+
14691487
static smt_termt dispatch_expr_to_smt_conversion(
14701488
const exprt &expr,
14711489
const sub_expression_mapt &converted,
@@ -1801,6 +1819,16 @@ static smt_termt dispatch_expr_to_smt_conversion(
18011819
{
18021820
return convert_expr_to_smt(*count_trailing_zeros, converted);
18031821
}
1822+
if(const auto r_or_w_ok = expr_try_dynamic_cast<r_or_w_ok_exprt>(expr))
1823+
{
1824+
return convert_expr_to_smt(*r_or_w_ok, converted);
1825+
}
1826+
if(
1827+
const auto pointer_in_range =
1828+
expr_try_dynamic_cast<pointer_in_range_exprt>(expr))
1829+
{
1830+
return convert_expr_to_smt(*pointer_in_range, converted);
1831+
}
18041832

18051833
UNIMPLEMENTED_FEATURE(
18061834
"Generation of SMT formula for unknown kind of expression: " +

0 commit comments

Comments
 (0)