Skip to content

Commit 20b7cef

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 6df0492 commit 20b7cef

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
@@ -204,6 +205,10 @@ literalt bv_pointerst::convert_rest(const exprt &expr)
204205
bv_utilst::representationt::UNSIGNED));
205206
}
206207
}
208+
else if(expr.id() == ID_r_ok || expr.id() == ID_w_ok || expr.id() == ID_rw_ok)
209+
return convert(simplify_expr(to_r_or_w_ok_expr(expr).lower(ns), ns));
210+
else if(expr.id() == ID_pointer_in_range)
211+
return convert(simplify_expr(to_pointer_in_range_expr(expr).lower(ns), ns));
207212

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

src/solvers/smt2/smt2_conv.cpp

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

5135+
// Perform rewrites that may introduce new symbols
5136+
for(auto it = lowered_expr.depth_begin(), itend = lowered_expr.depth_end();
5137+
it != itend;) // no ++it
5138+
{
5139+
if(auto r_or_w_ok = expr_try_dynamic_cast<r_or_w_ok_exprt>(*it))
5140+
{
5141+
exprt lowered = simplify_expr(r_or_w_ok->lower(ns), ns);
5142+
it.mutate() = lowered;
5143+
it.next_sibling_or_parent();
5144+
}
5145+
else if(
5146+
auto pointer_in_range =
5147+
expr_try_dynamic_cast<pointer_in_range_exprt>(*it))
5148+
{
5149+
exprt lowered = simplify_expr(pointer_in_range->lower(ns), ns);
5150+
it.mutate() = lowered;
5151+
it.next_sibling_or_parent();
5152+
}
5153+
else
5154+
++it;
5155+
}
5156+
51355157
// Now create symbols for all composite expressions present in lowered_expr:
51365158
find_symbols(lowered_expr);
51375159

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

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

1467+
static smt_termt convert_expr_to_smt(
1468+
const r_or_w_ok_exprt &r_or_w_ok,
1469+
const sub_expression_mapt &converted)
1470+
{
1471+
UNIMPLEMENTED_FEATURE(
1472+
"Generation of SMT formula for r/w/rw ok expression: " +
1473+
r_or_w_ok.pretty());
1474+
}
1475+
1476+
static smt_termt convert_expr_to_smt(
1477+
const pointer_in_range_exprt &pointer_in_range,
1478+
const sub_expression_mapt &converted)
1479+
{
1480+
UNIMPLEMENTED_FEATURE(
1481+
"Generation of SMT formula for pointer-in-range expression: " +
1482+
pointer_in_range.pretty());
1483+
}
1484+
14671485
static smt_termt dispatch_expr_to_smt_conversion(
14681486
const exprt &expr,
14691487
const sub_expression_mapt &converted,
@@ -1799,6 +1817,16 @@ static smt_termt dispatch_expr_to_smt_conversion(
17991817
{
18001818
return convert_expr_to_smt(*count_trailing_zeros, converted);
18011819
}
1820+
if(const auto r_or_w_ok = expr_try_dynamic_cast<r_or_w_ok_exprt>(expr))
1821+
{
1822+
return convert_expr_to_smt(*r_or_w_ok, converted);
1823+
}
1824+
if(
1825+
const auto pointer_in_range =
1826+
expr_try_dynamic_cast<pointer_in_range_exprt>(expr))
1827+
{
1828+
return convert_expr_to_smt(*pointer_in_range, converted);
1829+
}
18021830

18031831
UNIMPLEMENTED_FEATURE(
18041832
"Generation of SMT formula for unknown kind of expression: " +

0 commit comments

Comments
 (0)