Skip to content

Commit 27af11d

Browse files
committed
Always evaluate __CPROVER_{r,w}_ok and add a test
We did not have an explicit test of __CPROVER_{r,w}_ok, only implicit ones as we use these predicates in our model of the C library. While preparing a test it became apparent that the predicates are only evaluated when --pointer-check is set. This caused surprising behaviour as a negated predicate would result in failing assertions. Instead, make sure the expression is always evaluated, independent of --pointer-check. This requires always performing a local alias analysis, even when no pointer checks are enabled.
1 parent a139e2a commit 27af11d

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

regression/cbmc/r_w_ok1/main.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
int main()
5+
{
6+
int *p = NULL;
7+
8+
assert(!__CPROVER_r_ok(p, sizeof(int)));
9+
assert(!__CPROVER_w_ok(p, sizeof(int)));
10+
11+
p = malloc(sizeof(int));
12+
13+
assert(__CPROVER_r_ok(p, 1));
14+
assert(__CPROVER_w_ok(p, 1));
15+
assert(__CPROVER_r_ok(p, sizeof(int)));
16+
assert(__CPROVER_w_ok(p, sizeof(int)));
17+
18+
size_t n;
19+
char *arbitrary_size = malloc(n);
20+
21+
assert(__CPROVER_r_ok(arbitrary_size, n));
22+
assert(__CPROVER_w_ok(arbitrary_size, n));
23+
24+
assert(__CPROVER_r_ok(arbitrary_size, n + 1));
25+
assert(__CPROVER_w_ok(arbitrary_size, n + 1));
26+
}

regression/cbmc/r_w_ok1/test.desc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
4+
__CPROVER_[rw]_ok\(arbitrary_size, n \+ 1\): FAILURE$
5+
^\*\* 2 of 10 failed
6+
^VERIFICATION FAILED$
7+
^EXIT=10$
8+
^SIGNAL=0$
9+
--
10+
^warning: ignoring

src/analyses/goto_check.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,9 +1076,7 @@ void goto_checkt::pointer_validity_check(
10761076
goto_checkt::conditionst
10771077
goto_checkt::address_check(const exprt &address, const exprt &size)
10781078
{
1079-
if(!enable_pointer_check)
1080-
return {};
1081-
1079+
PRECONDITION(local_bitvector_analysis);
10821080
PRECONDITION(address.type().id() == ID_pointer);
10831081
const auto &pointer_type = to_pointer_type(address.type());
10841082

@@ -1700,9 +1698,8 @@ void goto_checkt::goto_check(
17001698

17011699
bool did_something = false;
17021700

1703-
if(enable_pointer_check)
1704-
local_bitvector_analysis =
1705-
util_make_unique<local_bitvector_analysist>(goto_function, ns);
1701+
local_bitvector_analysis =
1702+
util_make_unique<local_bitvector_analysist>(goto_function, ns);
17061703

17071704
goto_programt &goto_program=goto_function.body;
17081705

0 commit comments

Comments
 (0)