Skip to content

Commit a13bee2

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 fd9c7b6 commit a13bee2

File tree

7 files changed

+59
-4
lines changed

7 files changed

+59
-4
lines changed

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$

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
@@ -5030,6 +5030,28 @@ exprt smt2_convt::prepare_for_convert_expr(const exprt &expr)
50305030
!has_byte_operator(lowered_expr),
50315031
"lower_byte_operators should remove all byte operators");
50325032

5033+
// Perform rewrites that may introduce new symbols
5034+
for(auto it = lowered_expr.depth_begin(), itend = lowered_expr.depth_end();
5035+
it != itend;) // no ++it
5036+
{
5037+
if(auto r_or_w_ok = expr_try_dynamic_cast<r_or_w_ok_exprt>(*it))
5038+
{
5039+
exprt lowered = simplify_expr(r_or_w_ok->lower(ns), ns);
5040+
it.mutate() = lowered;
5041+
it.next_sibling_or_parent();
5042+
}
5043+
else if(
5044+
auto pointer_in_range =
5045+
expr_try_dynamic_cast<pointer_in_range_exprt>(*it))
5046+
{
5047+
exprt lowered = simplify_expr(pointer_in_range->lower(ns), ns);
5048+
it.mutate() = lowered;
5049+
it.next_sibling_or_parent();
5050+
}
5051+
else
5052+
++it;
5053+
}
5054+
50335055
// Now create symbols for all composite expressions present in lowered_expr:
50345056
find_symbols(lowered_expr);
50355057

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)