Skip to content

Commit 90f64fa

Browse files
authored
Merge pull request #6565 from tautschnig/simplify_rw_ok
Fix and cleanup __CPROVER_{r,w,rw}_ok expansion
2 parents 1c3f275 + 17325eb commit 90f64fa

File tree

5 files changed

+43
-32
lines changed

5 files changed

+43
-32
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/simplify.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+
--show-goto-functions
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
false ∨
8+
∨ false
9+
--
10+
__CPROVER_{r,w,rw}_ok must be rewritten everywhere, and the resulting expression
11+
should be simplified (and, therefore, not contain "false" in a disjunction).

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.

regression/validate-trace-xml-schema/check.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
['integer-assignments1', 'integer-typecheck.desc'],
2626
['destructors', 'compound_literal.desc'],
2727
['destructors', 'enter_lexical_block.desc'],
28+
['r_w_ok9', 'simplify.desc'],
2829
['reachability-slice-interproc2', 'test.desc'],
2930
# this one wants show-properties instead producing a trace
3031
['show_properties1', 'test.desc'],

src/analyses/goto_check_c.cpp

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,10 @@ optionalt<exprt> goto_check_ct::rw_ok_check(exprt expr)
19191919
for(const auto &c : conditions)
19201920
conjuncts.push_back(c.assertion);
19211921

1922-
return conjunction(conjuncts);
1922+
exprt c = conjunction(conjuncts);
1923+
if(enable_simplify)
1924+
simplify(c, ns);
1925+
return c;
19231926
}
19241927
else if(modified)
19251928
return std::move(expr);
@@ -2068,16 +2071,6 @@ void goto_check_ct::goto_check(
20682071
if(i.has_condition())
20692072
{
20702073
check(i.get_condition());
2071-
2072-
if(has_subexpr(i.get_condition(), [](const exprt &expr) {
2073-
return expr.id() == ID_r_ok || expr.id() == ID_w_ok ||
2074-
expr.id() == ID_rw_ok;
2075-
}))
2076-
{
2077-
auto rw_ok_cond = rw_ok_check(i.get_condition());
2078-
if(rw_ok_cond.has_value())
2079-
i.set_condition(*rw_ok_cond);
2080-
}
20812074
}
20822075

20832076
// magic ERROR label?
@@ -2129,16 +2122,6 @@ void goto_check_ct::goto_check(
21292122

21302123
// the LHS might invalidate any assertion
21312124
invalidate(assign_lhs);
2132-
2133-
if(has_subexpr(assign_rhs, [](const exprt &expr) {
2134-
return expr.id() == ID_r_ok || expr.id() == ID_w_ok ||
2135-
expr.id() == ID_rw_ok;
2136-
}))
2137-
{
2138-
auto rw_ok_cond = rw_ok_check(assign_rhs);
2139-
if(rw_ok_cond.has_value())
2140-
i.assign_rhs_nonconst() = *rw_ok_cond;
2141-
}
21422125
}
21432126
else if(i.is_function_call())
21442127
{
@@ -2156,17 +2139,6 @@ void goto_check_ct::goto_check(
21562139
check(i.return_value());
21572140
// the return value invalidate any assertion
21582141
invalidate(i.return_value());
2159-
2160-
if(has_subexpr(i.return_value(), [](const exprt &expr) {
2161-
return expr.id() == ID_r_ok || expr.id() == ID_w_ok ||
2162-
expr.id() == ID_rw_ok;
2163-
}))
2164-
{
2165-
exprt &return_value = i.return_value();
2166-
auto rw_ok_cond = rw_ok_check(return_value);
2167-
if(rw_ok_cond.has_value())
2168-
return_value = *rw_ok_cond;
2169-
}
21702142
}
21712143
else if(i.is_throw())
21722144
{
@@ -2288,6 +2260,8 @@ void goto_check_ct::goto_check(
22882260
}
22892261
}
22902262

2263+
i.transform([this](exprt expr) { return rw_ok_check(expr); });
2264+
22912265
for(auto &instruction : new_code.instructions)
22922266
{
22932267
if(instruction.source_location().is_nil())

0 commit comments

Comments
 (0)