Skip to content

Commit 3f9ae1c

Browse files
committed
__CPROVER_{r,w,rw}_ok must be rewritten everywhere
The previous code supported occurrence of __CPROVER_{r,w,rw}_ok in some parts of instructions only.
1 parent 169dc18 commit 3f9ae1c

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

regression/cbmc/r_w_ok9/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
int check(int cond)
2+
{
3+
return cond;
4+
}
5+
6+
int main()
7+
{
8+
int x;
9+
int *p = &x;
10+
if(check(!__CPROVER_r_ok(p, sizeof(int))))
11+
{
12+
__CPROVER_assert(0, "must be unreachable");
13+
}
14+
}

regression/cbmc/r_w_ok9/test.desc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
VERIFICATION SUCCESSFUL
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
--
10+
__CPROVER_{r,w,rw}_ok must be rewritten everywhere, which includes function call
11+
arguments.

src/analyses/goto_check_c.cpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,16 +2067,6 @@ void goto_check_ct::goto_check(
20672067
if(i.has_condition())
20682068
{
20692069
check(i.get_condition());
2070-
2071-
if(has_subexpr(i.get_condition(), [](const exprt &expr) {
2072-
return expr.id() == ID_r_ok || expr.id() == ID_w_ok ||
2073-
expr.id() == ID_rw_ok;
2074-
}))
2075-
{
2076-
auto rw_ok_cond = rw_ok_check(i.get_condition());
2077-
if(rw_ok_cond.has_value())
2078-
i.set_condition(*rw_ok_cond);
2079-
}
20802070
}
20812071

20822072
// magic ERROR label?
@@ -2128,16 +2118,6 @@ void goto_check_ct::goto_check(
21282118

21292119
// the LHS might invalidate any assertion
21302120
invalidate(assign_lhs);
2131-
2132-
if(has_subexpr(assign_rhs, [](const exprt &expr) {
2133-
return expr.id() == ID_r_ok || expr.id() == ID_w_ok ||
2134-
expr.id() == ID_rw_ok;
2135-
}))
2136-
{
2137-
auto rw_ok_cond = rw_ok_check(assign_rhs);
2138-
if(rw_ok_cond.has_value())
2139-
i.assign_rhs_nonconst() = *rw_ok_cond;
2140-
}
21412121
}
21422122
else if(i.is_function_call())
21432123
{
@@ -2155,17 +2135,6 @@ void goto_check_ct::goto_check(
21552135
check(i.return_value());
21562136
// the return value invalidate any assertion
21572137
invalidate(i.return_value());
2158-
2159-
if(has_subexpr(i.return_value(), [](const exprt &expr) {
2160-
return expr.id() == ID_r_ok || expr.id() == ID_w_ok ||
2161-
expr.id() == ID_rw_ok;
2162-
}))
2163-
{
2164-
exprt &return_value = i.return_value();
2165-
auto rw_ok_cond = rw_ok_check(return_value);
2166-
if(rw_ok_cond.has_value())
2167-
return_value = *rw_ok_cond;
2168-
}
21692138
}
21702139
else if(i.is_throw())
21712140
{
@@ -2287,6 +2256,8 @@ void goto_check_ct::goto_check(
22872256
}
22882257
}
22892258

2259+
i.transform([this](exprt expr) { return rw_ok_check(expr); });
2260+
22902261
for(auto &instruction : new_code.instructions)
22912262
{
22922263
if(instruction.source_location().is_nil())

0 commit comments

Comments
 (0)