Skip to content

Commit df8ef89

Browse files
committed
Support __CPROVER_{r,w}_ok in assignments, assumptions, gotos, returns
We previously only evaluated __CPROVER_{r,w}_ok in assertions (without telling anyone that was the case). Instead, evaluate it in all contexts where it might reasonably appear.
1 parent 27af11d commit df8ef89

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

regression/cbmc/r_w_ok2/main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
3+
int main()
4+
{
5+
int *p = (int *)0;
6+
7+
_Bool not_ok = !__CPROVER_r_ok(p, sizeof(int));
8+
assert(not_ok);
9+
10+
if(__CPROVER_w_ok(p, sizeof(int)))
11+
assert(0);
12+
}

regression/cbmc/r_w_ok2/test.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

src/analyses/goto_check.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,8 +1718,19 @@ void goto_checkt::goto_check(
17181718
assertions.clear();
17191719

17201720
if(i.has_condition())
1721+
{
17211722
check(i.get_condition());
17221723

1724+
if(has_subexpr(i.get_condition(), [](const exprt &expr) {
1725+
return expr.id() == ID_r_ok || expr.id() == ID_w_ok;
1726+
}))
1727+
{
1728+
auto rw_ok_cond = rw_ok_check(i.get_condition());
1729+
if(rw_ok_cond.has_value())
1730+
i.set_condition(*rw_ok_cond);
1731+
}
1732+
}
1733+
17231734
// magic ERROR label?
17241735
for(const auto &label : error_labels)
17251736
{
@@ -1762,6 +1773,15 @@ void goto_checkt::goto_check(
17621773

17631774
// the LHS might invalidate any assertion
17641775
invalidate(code_assign.lhs());
1776+
1777+
if(has_subexpr(i.code.op1(), [](const exprt &expr) {
1778+
return expr.id() == ID_r_ok || expr.id() == ID_w_ok;
1779+
}))
1780+
{
1781+
auto rw_ok_cond = rw_ok_check(i.code.op1());
1782+
if(rw_ok_cond.has_value())
1783+
i.code.op1() = *rw_ok_cond;
1784+
}
17651785
}
17661786
else if(i.is_function_call())
17671787
{
@@ -1810,6 +1830,15 @@ void goto_checkt::goto_check(
18101830
check(i.code.op0());
18111831
// the return value invalidate any assertion
18121832
invalidate(i.code.op0());
1833+
1834+
if(has_subexpr(i.code.op0(), [](const exprt &expr) {
1835+
return expr.id() == ID_r_ok || expr.id() == ID_w_ok;
1836+
}))
1837+
{
1838+
auto rw_ok_cond = rw_ok_check(i.code.op0());
1839+
if(rw_ok_cond.has_value())
1840+
i.code.op0() = *rw_ok_cond;
1841+
}
18131842
}
18141843
}
18151844
else if(i.is_throw())
@@ -1841,10 +1870,6 @@ void goto_checkt::goto_check(
18411870
{
18421871
bool is_user_provided=i.source_location.get_bool("user-provided");
18431872

1844-
auto rw_ok_cond = rw_ok_check(i.get_condition());
1845-
if(rw_ok_cond.has_value())
1846-
i.set_condition(*rw_ok_cond);
1847-
18481873
if((is_user_provided && !enable_assertions &&
18491874
i.source_location.get_property_class()!="error label") ||
18501875
(!is_user_provided && !enable_built_in_assertions))

0 commit comments

Comments
 (0)