@@ -17,11 +17,11 @@ Date: July 2021
1717
1818#include < langapi/language_util.h>
1919
20- #include < util/arith_tools.h>
21- #include < util/c_types.h>
2220#include < util/pointer_offset_size.h>
2321#include < util/pointer_predicates.h>
2422
23+ #include " utils.h"
24+
2525assigns_clauset::targett::targett (
2626 const assigns_clauset &parent,
2727 const exprt &expr)
@@ -46,27 +46,16 @@ exprt assigns_clauset::targett::normalize(const exprt &expr)
4646exprt assigns_clauset::targett::generate_containment_check (
4747 const address_of_exprt &lhs_address) const
4848{
49- exprt::operandst address_validity;
50- exprt::operandst containment_check;
51-
52- // __CPROVER_w_ok(target, sizeof(target))
53- address_validity.push_back (w_ok_exprt (
54- address,
55- size_of_expr (dereference_exprt (address).type (), parent.ns ).value ()));
56-
57- // __CPROVER_w_ok(lhs, sizeof(lhs))
58- address_validity.push_back (w_ok_exprt (
59- lhs_address,
60- size_of_expr (dereference_exprt (lhs_address).type (), parent.ns ).value ()));
49+ const auto address_validity = and_exprt{
50+ all_dereferences_are_valid (dereference_exprt{address}, parent.ns ),
51+ all_dereferences_are_valid (dereference_exprt{lhs_address}, parent.ns )};
6152
62- // __CPROVER_same_object(lhs, target)
53+ exprt::operandst containment_check;
6354 containment_check.push_back (same_object (lhs_address, address));
6455
6556 // If assigns target was a dereference, comparing objects is enough
66- // and the resulting condition will be
67- // __CPROVER_w_ok(target, sizeof(target))
68- // && __CPROVER_w_ok(lhs, sizeof(lhs))
69- // ==> __CPROVER_same_object(lhs, target)
57+ // and the resulting condition will be:
58+ // VALID(self) && VALID(lhs) ==> __CPROVER_same_object(lhs, self)
7059 if (id != ID_dereference)
7160 {
7261 const auto lhs_offset = pointer_offset (lhs_address);
@@ -89,19 +78,17 @@ exprt assigns_clauset::targett::generate_containment_check(
8978 own_offset);
9079
9180 // (sizeof(lhs) + __CPROVER_offset(lhs)) <=
92- // (sizeof(target ) + __CPROVER_offset(target ))
81+ // (sizeof(self ) + __CPROVER_offset(self ))
9382 containment_check.push_back (
9483 binary_relation_exprt (lhs_region, ID_le, own_region));
9584 }
9685
97- // __CPROVER_w_ok(target, sizeof(target))
98- // && __CPROVER_w_ok(lhs, sizeof(lhs))
99- // ==> __CPROVER_same_object(lhs, target)
100- // && __CPROVER_offset(lhs) >= __CPROVER_offset(target)
101- // && (sizeof(lhs) + __CPROVER_offset(lhs)) <=
102- // (sizeof(target) + __CPROVER_offset(target))
103- return binary_relation_exprt (
104- conjunction (address_validity), ID_implies, conjunction (containment_check));
86+ // VALID(self) && VALID(lhs)
87+ // ==> __CPROVER_same_object(lhs, self)
88+ // && __CPROVER_offset(lhs) >= __CPROVER_offset(self)
89+ // && (sizeof(lhs) + __CPROVER_offset(lhs)) <=
90+ // (sizeof(self) + __CPROVER_offset(self))
91+ return or_exprt{not_exprt{address_validity}, conjunction (containment_check)};
10592}
10693
10794assigns_clauset::assigns_clauset (
@@ -150,12 +137,13 @@ goto_programt assigns_clauset::generate_havoc_code() const
150137 modifiest modifies;
151138 for (const auto &target : global_write_set)
152139 modifies.insert (target.address .object ());
153-
154140 for (const auto &target : local_write_set)
155141 modifies.insert (target.address .object ());
156142
157143 goto_programt havoc_statements;
158- append_havoc_code (location, modifies, havoc_statements);
144+ havoc_if_validt havoc_gen (modifies, ns);
145+ havoc_gen.append_full_havoc_code (location, havoc_statements);
146+
159147 return havoc_statements;
160148}
161149
0 commit comments