Skip to content

Commit bfa3212

Browse files
committed
Move rw_ok rewriting to separate pass
This reverts selected changes from "r/w/rw_ok and pointer_in_range depend on deallocated and dead_object" for transformations of goto programs can now safely introduce rw_ok expressions into the goto program.
1 parent a3d8822 commit bfa3212

File tree

16 files changed

+128
-68
lines changed

16 files changed

+128
-68
lines changed

regression/cbmc/realloc-should-not-free-on-failure-to-allocate/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE new-smt-backend
22
test.c
33
--malloc-may-fail --malloc-fail-null
4-
^\[free.precondition.\d+] line \d+ double free: SUCCESS$
4+
^\[main.precondition_instance.\d+] line \d+ double free: SUCCESS$
55
^VERIFICATION SUCCESSFUL$
66
^EXIT=0$
77
^SIGNAL=0$

regression/goto-cc-goto-analyzer/instrument_preconditions_locations/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test.c
44
^EXIT=0$
55
^SIGNAL=0$
66
Checking assertions
7-
^\[free.precondition.1\] line \d+ free argument must be NULL or valid pointer: SUCCESS
7+
^\[EVP_MD_CTX_free.precondition_instance.1\] line \d+ free argument must be NULL or valid pointer: SUCCESS
88
--
99
Invariant check failed
1010
--

src/cbmc/cbmc_parse_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
406406
PARSE_OPTIONS_GOTO_TRACE(cmdline, options);
407407

408408
// Options for process_goto_program
409+
options.set_option("rewrite-rw-ok", true);
409410
options.set_option("rewrite-union", true);
410411

411412
if(cmdline.isset("smt1"))

src/cprover/state_encoding.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,6 @@ exprt state_encodingt::evaluate_expr_rec(
294294
: ID_state_rw_ok;
295295
return ternary_exprt(new_id, state, pointer, size, what.type());
296296
}
297-
else if(
298-
const auto r_or_w_ok_expr =
299-
expr_try_dynamic_cast<prophecy_r_or_w_ok_exprt>(what))
300-
{
301-
// we replace prophecy expressions by our state
302-
auto pointer =
303-
evaluate_expr_rec(loc, state, r_or_w_ok_expr->pointer(), bound_symbols);
304-
auto size =
305-
evaluate_expr_rec(loc, state, r_or_w_ok_expr->size(), bound_symbols);
306-
auto new_id = what.id() == ID_prophecy_r_ok ? ID_state_r_ok
307-
: what.id() == ID_prophecy_w_ok ? ID_state_w_ok
308-
: ID_state_rw_ok;
309-
return ternary_exprt(new_id, state, pointer, size, what.type());
310-
}
311297
else if(what.id() == ID_is_cstring)
312298
{
313299
// we need to add the state

src/goto-analyzer/goto_analyzer_parse_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ int goto_analyzer_parse_optionst::doit()
393393

394394
// Preserve backwards compatibility in processing
395395
options.set_option("partial-inline", true);
396+
options.set_option("rewrite-rw-ok", false);
396397
options.set_option("rewrite-union", false);
397398
options.set_option("remove-returns", true);
398399

src/goto-diff/goto_diff_parse_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void goto_diff_parse_optionst::get_command_line_options(optionst &options)
6565
options.set_option("show-properties", cmdline.isset("show-properties"));
6666

6767
// Options for process_goto_program
68+
options.set_option("rewrite-rw-ok", false);
6869
options.set_option("rewrite-union", true);
6970
}
7071

src/goto-instrument/contracts/instrument_spec_assigns.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -644,13 +644,9 @@ exprt instrument_spec_assignst::target_validity_expr(
644644
// (or is NULL if we allow it explicitly).
645645
// This assertion will be falsified whenever `start_address` is invalid or
646646
// not of the right size (or is NULL if we do not allow it explicitly).
647-
symbol_exprt deallocated =
648-
ns.lookup(CPROVER_PREFIX "deallocated").symbol_expr();
649-
symbol_exprt dead = ns.lookup(CPROVER_PREFIX "dead_object").symbol_expr();
650-
auto result = or_exprt{
651-
not_exprt{car.condition()},
652-
prophecy_w_ok_exprt{
653-
car.target_start_address(), car.target_size(), deallocated, dead}};
647+
auto result =
648+
or_exprt{not_exprt{car.condition()},
649+
w_ok_exprt{car.target_start_address(), car.target_size()}};
654650

655651
if(allow_null_target)
656652
result.add_to_operands(null_object(car.target_start_address()));

src/goto-instrument/contracts/utils.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,7 @@ exprt all_dereferences_are_valid(const exprt &expr, const namespacet &ns)
178178
const auto size_of_expr_opt = size_of_expr(expr.type(), ns);
179179
CHECK_RETURN(size_of_expr_opt.has_value());
180180

181-
symbol_exprt deallocated =
182-
ns.lookup(CPROVER_PREFIX "deallocated").symbol_expr();
183-
symbol_exprt dead = ns.lookup(CPROVER_PREFIX "dead_object").symbol_expr();
184-
validity_checks.push_back(prophecy_r_ok_exprt{
185-
deref->pointer(), *size_of_expr_opt, deallocated, dead});
181+
validity_checks.push_back(r_ok_exprt{deref->pointer(), *size_of_expr_opt});
186182
}
187183

188184
for(const auto &op : expr.operands())

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Author: Daniel Kroening, [email protected]
4545
#include <goto-programs/remove_unused_functions.h>
4646
#include <goto-programs/remove_virtual_functions.h>
4747
#include <goto-programs/restrict_function_pointers.h>
48+
#include <goto-programs/rewrite_rw_ok.h>
4849
#include <goto-programs/rewrite_union.h>
4950
#include <goto-programs/set_properties.h>
5051
#include <goto-programs/show_properties.h>
@@ -1767,6 +1768,7 @@ void goto_instrument_parse_optionst::instrument_goto_program()
17671768
{
17681769
do_indirect_call_and_rtti_removal();
17691770
do_remove_returns();
1771+
rewrite_rw_ok(goto_model);
17701772

17711773
log.warning() << "**** WARNING: Experimental option --full-slice, "
17721774
<< "analysis results may be unsound. See "

src/goto-programs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ SRC = allocate_objects.cpp \
5656
remove_vector.cpp \
5757
remove_virtual_functions.cpp \
5858
restrict_function_pointers.cpp \
59+
rewrite_rw_ok.cpp \
5960
rewrite_union.cpp \
6061
resolve_inherited_component.cpp \
6162
safety_checker.cpp \

0 commit comments

Comments
 (0)