Skip to content

Commit f75bc2f

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 d3d58a0 commit f75bc2f

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-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: 30 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,16 @@ void goto_checkt::goto_check(
17621773

17631774
// the LHS might invalidate any assertion
17641775
invalidate(code_assign.lhs());
1776+
1777+
if(has_subexpr(code_assign.rhs(), [](const exprt &expr) {
1778+
return expr.id() == ID_r_ok || expr.id() == ID_w_ok;
1779+
}))
1780+
{
1781+
exprt &rhs = to_code_assign(i.code).rhs();
1782+
auto rw_ok_cond = rw_ok_check(rhs);
1783+
if(rw_ok_cond.has_value())
1784+
rhs = *rw_ok_cond;
1785+
}
17651786
}
17661787
else if(i.is_function_call())
17671788
{
@@ -1810,6 +1831,15 @@ void goto_checkt::goto_check(
18101831
check(i.code.op0());
18111832
// the return value invalidate any assertion
18121833
invalidate(i.code.op0());
1834+
1835+
if(has_subexpr(i.code.op0(), [](const exprt &expr) {
1836+
return expr.id() == ID_r_ok || expr.id() == ID_w_ok;
1837+
}))
1838+
{
1839+
auto rw_ok_cond = rw_ok_check(i.code.op0());
1840+
if(rw_ok_cond.has_value())
1841+
i.code.op0() = *rw_ok_cond;
1842+
}
18131843
}
18141844
}
18151845
else if(i.is_throw())
@@ -1841,10 +1871,6 @@ void goto_checkt::goto_check(
18411871
{
18421872
bool is_user_provided=i.source_location.get_bool("user-provided");
18431873

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-
18481874
if((is_user_provided && !enable_assertions &&
18491875
i.source_location.get_property_class()!="error label") ||
18501876
(!is_user_provided && !enable_built_in_assertions))

0 commit comments

Comments
 (0)