@@ -17,11 +17,11 @@ Date: July 2021
17
17
18
18
#include < langapi/language_util.h>
19
19
20
- #include < util/arith_tools.h>
21
- #include < util/c_types.h>
22
20
#include < util/pointer_offset_size.h>
23
21
#include < util/pointer_predicates.h>
24
22
23
+ #include " utils.h"
24
+
25
25
assigns_clauset::targett::targett (
26
26
const assigns_clauset &parent,
27
27
const exprt &expr)
@@ -46,27 +46,16 @@ exprt assigns_clauset::targett::normalize(const exprt &expr)
46
46
exprt assigns_clauset::targett::generate_containment_check (
47
47
const address_of_exprt &lhs_address) const
48
48
{
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 )};
61
52
62
- // __CPROVER_same_object(lhs, target)
53
+ exprt::operandst containment_check;
63
54
containment_check.push_back (same_object (lhs_address, address));
64
55
65
56
// 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)
70
59
if (id != ID_dereference)
71
60
{
72
61
const auto lhs_offset = pointer_offset (lhs_address);
@@ -89,19 +78,17 @@ exprt assigns_clauset::targett::generate_containment_check(
89
78
own_offset);
90
79
91
80
// (sizeof(lhs) + __CPROVER_offset(lhs)) <=
92
- // (sizeof(target ) + __CPROVER_offset(target ))
81
+ // (sizeof(self ) + __CPROVER_offset(self ))
93
82
containment_check.push_back (
94
83
binary_relation_exprt (lhs_region, ID_le, own_region));
95
84
}
96
85
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)};
105
92
}
106
93
107
94
assigns_clauset::assigns_clauset (
@@ -150,12 +137,13 @@ goto_programt assigns_clauset::generate_havoc_code() const
150
137
modifiest modifies;
151
138
for (const auto &target : global_write_set)
152
139
modifies.insert (target.address .object ());
153
-
154
140
for (const auto &target : local_write_set)
155
141
modifies.insert (target.address .object ());
156
142
157
143
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
+
159
147
return havoc_statements;
160
148
}
161
149
0 commit comments