Skip to content

Commit 3c2778e

Browse files
Add functions to combine property results
Used to update the properties map and to compute the overall result.
1 parent b1587fa commit 3c2778e

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

src/goto-checker/properties.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,100 @@ count_properties(const propertiest &properties, property_statust status)
144144
}
145145
return count;
146146
}
147+
148+
/// Update with the preference order
149+
/// 1. old non-UNKNOWN/non-NOT_CHECKED status
150+
/// 2. new non-UNKNOWN/non-NOT_CHECKED status
151+
/// 3. UNKNOWN
152+
/// 4. NOT_CHECKED
153+
/// Suitable for updating property status
154+
property_statust &operator|=(property_statust &a, property_statust const &b)
155+
{
156+
// non-monotonic use is likely a bug
157+
PRECONDITION(
158+
a == property_statust::NOT_CHECKED ||
159+
(a == property_statust::UNKNOWN && b != property_statust::NOT_CHECKED) ||
160+
a == b);
161+
switch(a)
162+
{
163+
case property_statust::NOT_CHECKED:
164+
case property_statust::UNKNOWN:
165+
a = b;
166+
return a;
167+
case property_statust::ERROR:
168+
case property_statust::PASS:
169+
case property_statust::NOT_REACHABLE:
170+
case property_statust::FAIL:
171+
return a;
172+
}
173+
UNREACHABLE;
174+
}
175+
176+
/// Update with the preference order
177+
/// 1. ERROR
178+
/// 2. FAIL
179+
/// 3. UNKNOWN
180+
/// 4. NOT_CHECKED
181+
/// 5. NOT_REACHABLE
182+
/// 6. PASS
183+
/// Suitable for computing overall results
184+
property_statust &operator&=(property_statust &a, property_statust const &b)
185+
{
186+
switch(a)
187+
{
188+
case property_statust::ERROR:
189+
a = b;
190+
return a;
191+
case property_statust::FAIL:
192+
a = (b == property_statust::ERROR ? b : a);
193+
return a;
194+
case property_statust::UNKNOWN:
195+
a = (b == property_statust::ERROR || b == property_statust::FAIL ? b : a);
196+
return a;
197+
case property_statust::NOT_CHECKED:
198+
a =
199+
(b != property_statust::PASS && b != property_statust::NOT_REACHABLE ? b
200+
: a);
201+
return a;
202+
case property_statust::NOT_REACHABLE:
203+
a = (b != property_statust::PASS ? b : a);
204+
return a;
205+
case property_statust::PASS:
206+
a = (b == property_statust::PASS ? a : b);
207+
return a;
208+
}
209+
UNREACHABLE;
210+
}
211+
212+
/// Determines the overall result corresponding from the given properties
213+
/// That is PASS if all properties are PASS or NOT_CHECKED,
214+
/// FAIL if at least one property is FAIL and no property is ERROR,
215+
/// UNKNOWN if no property is FAIL or ERROR and
216+
/// at least one property is UNKNOWN,
217+
/// ERROR if at least one property is error.
218+
resultt determine_result(const propertiest &properties)
219+
{
220+
property_statust status = property_statust::PASS;
221+
for(const auto &property_pair : properties)
222+
{
223+
status &= property_pair.second.status;
224+
}
225+
switch(status)
226+
{
227+
case property_statust::NOT_CHECKED:
228+
// If we have unchecked properties then we don't know.
229+
return resultt::UNKNOWN;
230+
case property_statust::UNKNOWN:
231+
return resultt::UNKNOWN;
232+
case property_statust::NOT_REACHABLE:
233+
// If a property is not reachable then overall it's still a PASS.
234+
return resultt::PASS;
235+
case property_statust::PASS:
236+
return resultt::PASS;
237+
case property_statust::FAIL:
238+
return resultt::FAIL;
239+
case property_statust::ERROR:
240+
return resultt::ERROR;
241+
}
242+
UNREACHABLE;
243+
}

src/goto-checker/properties.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,8 @@ int result_to_exit_code(resultt result);
8989
/// Return the number of properties with given \p status
9090
std::size_t count_properties(const propertiest &, property_statust);
9191

92+
property_statust &operator|=(property_statust &, property_statust const &);
93+
property_statust &operator&=(property_statust &, property_statust const &);
94+
resultt determine_result(const propertiest &properties);
95+
9296
#endif // CPROVER_GOTO_CHECKER_PROPERTIES_H

0 commit comments

Comments
 (0)