Skip to content

Commit c4b19af

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 261a77a commit c4b19af

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+
--pointer-check
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
@@ -1727,8 +1727,19 @@ void goto_checkt::goto_check(
17271727
assertions.clear();
17281728

17291729
if(i.has_condition())
1730+
{
17301731
check(i.get_condition());
17311732

1733+
if(has_subexpr(i.get_condition(), [](const exprt &expr) {
1734+
return expr.id() == ID_r_ok || expr.id() == ID_w_ok;
1735+
}))
1736+
{
1737+
auto rw_ok_cond = rw_ok_check(i.get_condition(), false);
1738+
if(rw_ok_cond.has_value())
1739+
i.set_condition(*rw_ok_cond);
1740+
}
1741+
}
1742+
17321743
// magic ERROR label?
17331744
for(const auto &label : error_labels)
17341745
{
@@ -1771,6 +1782,15 @@ void goto_checkt::goto_check(
17711782

17721783
// the LHS might invalidate any assertion
17731784
invalidate(code_assign.lhs());
1785+
1786+
if(has_subexpr(i.code.op1(), [](const exprt &expr) {
1787+
return expr.id() == ID_r_ok || expr.id() == ID_w_ok;
1788+
}))
1789+
{
1790+
auto rw_ok_cond = rw_ok_check(i.code.op1(), false);
1791+
if(rw_ok_cond.has_value())
1792+
i.code.op1() = *rw_ok_cond;
1793+
}
17741794
}
17751795
else if(i.is_function_call())
17761796
{
@@ -1819,6 +1839,15 @@ void goto_checkt::goto_check(
18191839
check(i.code.op0());
18201840
// the return value invalidate any assertion
18211841
invalidate(i.code.op0());
1842+
1843+
if(has_subexpr(i.code.op0(), [](const exprt &expr) {
1844+
return expr.id() == ID_r_ok || expr.id() == ID_w_ok;
1845+
}))
1846+
{
1847+
auto rw_ok_cond = rw_ok_check(i.code.op0(), false);
1848+
if(rw_ok_cond.has_value())
1849+
i.code.op0() = *rw_ok_cond;
1850+
}
18221851
}
18231852
}
18241853
else if(i.is_throw())
@@ -1850,10 +1879,6 @@ void goto_checkt::goto_check(
18501879
{
18511880
bool is_user_provided=i.source_location.get_bool("user-provided");
18521881

1853-
auto rw_ok_cond = rw_ok_check(i.get_condition(), false);
1854-
if(rw_ok_cond.has_value())
1855-
i.set_condition(*rw_ok_cond);
1856-
18571882
if((is_user_provided && !enable_assertions &&
18581883
i.source_location.get_property_class()!="error label") ||
18591884
(!is_user_provided && !enable_built_in_assertions))

0 commit comments

Comments
 (0)