Skip to content

Commit e913535

Browse files
authored
Merge pull request #6893 from diffblue/unsigned_pointer_offset
make pointer_offset_exprt unsigned
2 parents fb65095 + 7cb83c1 commit e913535

File tree

24 files changed

+229
-115
lines changed

24 files changed

+229
-115
lines changed

regression/cbmc-incr-smt2/pointers-conversions/byte_update.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Assumption:
1010
file byte_update\.c line \d+ function main
1111
offset >= 0u && offset < 4u
1212
State \d+ file byte_update\.c function main line \d+ thread \d+
13-
byte_extract_little_endian\(x, \(signed long( long)? int\)offset, uint8_t\)=1 \(00000001\)
13+
byte_extract_little_endian\(x, \(.*\)offset, uint8_t\)=1 \(00000001\)
1414
Violated property:
1515
file byte_update.c function main line \d+ thread \d+
1616
assertion x != 256u

regression/cbmc-library/free-01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
main.c
33
--pointer-check --bounds-check --stop-on-fail
4-
free argument must be (NULL or valid pointer|dynamic object)
4+
free argument (must be (NULL or valid pointer|dynamic object)|has offset zero)
55
^EXIT=10$
66
^SIGNAL=0$
77
^VERIFICATION FAILED$

regression/cbmc-library/strlen-02/test-c-with-string-abstraction.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
test.c
33
--string-abstraction --show-goto-functions
4-
ASSIGN strlen#return_value := cast\(cast\(\*strlen::s::s#str\.length, signedbv\[.*\]\) - pointer_offset\(strlen::s\), unsignedbv\[.*\]\)
4+
ASSIGN strlen#return_value := \*strlen::s::s#str\.length - pointer_offset\(strlen::s\)
55
^EXIT=0$
66
^SIGNAL=0$
77
--

regression/cbmc-primitives/pointer-offset-01/test-no-cp.desc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ main.c
33
--no-simplify --no-propagation
44
^EXIT=10$
55
^SIGNAL=0$
6-
\[main.assertion.1\] line \d+ assertion __CPROVER_POINTER_OFFSET\(p\) >= 0: FAILURE
6+
\[main.assertion.1\] line \d+ assertion __CPROVER_POINTER_OFFSET\(p\) >= 0: SUCCESS
77
\[main.assertion.2\] line \d+ assertion __CPROVER_POINTER_OFFSET\(p\) < 0: FAILURE
88
--
99
^warning: ignoring
1010
--
11-
Check that both positive and negative offsets can be chosen for uninitialized
12-
pointers. We use --no-simplify and --no-propagation to ensure that the case is
13-
not solved by the constant propagation and thus tests the constraint encoding.
11+
Check that positive offsets can be chosen for uninitialized pointers. We
12+
use --no-simplify and --no-propagation to ensure that the case is not solved
13+
by the constant propagation and thus tests the constraint encoding.

regression/cbmc-primitives/pointer-offset-01/test.desc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ main.c
33

44
^EXIT=10$
55
^SIGNAL=0$
6-
\[main.assertion.1\] line \d+ assertion __CPROVER_POINTER_OFFSET\(p\) >= 0: FAILURE
6+
\[main.assertion.1\] line \d+ assertion __CPROVER_POINTER_OFFSET\(p\) >= 0: SUCCESS
77
\[main.assertion.2\] line \d+ assertion __CPROVER_POINTER_OFFSET\(p\) < 0: FAILURE
88
--
99
^warning: ignoring
1010
--
11-
For uninitialised pointers, CBMC chooses a nondeterministic value (though no memory
12-
is allocated). Since the offset of pointers is signed, negative offsets should be
13-
able to be chosen (along with positive ones) non-deterministically.
14-
`__CPROVER_POINTER_OFFSET` is the CBMC primitive that gets the pointer offset
15-
from the base address of the object. This test guards this, and especially
16-
against the case where we could only observe some cases where offsets were only
17-
positive (in some CI configurations, for instance).
11+
For uninitialised pointers, CBMC chooses a nondeterministic value (though no
12+
memory is allocated). Since the offset of pointers is unsigned, negative
13+
offsets cannot be chosen. `__CPROVER_POINTER_OFFSET` is the CBMC primitive
14+
that gets the pointer offset from the base address of the object. This test
15+
guards this.

regression/cbmc/address_space_size_limit3/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE thorough-smt-backend
22
main.i
3-
--32 --little-endian --object-bits 25 --pointer-check
3+
--32 --little-endian --object-bits 26 --pointer-check
44
^EXIT=10$
55
^SIGNAL=0$
66
^VERIFICATION FAILED$

regression/cbmc/memory_allocation2/test.desc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ main.c
33
--bounds-check
44
^EXIT=10$
55
^SIGNAL=0$
6-
^\[main\.array_bounds\.[1-5]\] .*: SUCCESS$
7-
^\[main\.array_bounds\.[67]\] line 38 array.buffer (dynamic object )?upper bound in buffers\[\(signed long (long )?int\)0\]->buffer\[\(signed long (long )?int\)100\]: FAILURE$
8-
^\*\* 1 of 6 failed
6+
^\[main\.array_bounds\.[1-2]\] .*: SUCCESS$
7+
^\[main\.array_bounds\.3\] line 38 array.buffer (dynamic object )?upper bound in buffers\[\(signed long (long )?int\)0\]->buffer\[\(signed long (long )?int\)100\]: FAILURE$
8+
^\*\* 1 of 3 failed
99
^VERIFICATION FAILED$
1010
--
1111
^warning: ignoring
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
int main(void)
5+
{
6+
size_t size;
7+
size_t max_malloc_size = __CPROVER_max_malloc_size;
8+
__CPROVER_assume(0 <= size && size <= max_malloc_size);
9+
char *lb = malloc(size);
10+
size_t offset_lb = __CPROVER_POINTER_OFFSET(lb);
11+
size_t object_lb = __CPROVER_POINTER_OBJECT(lb);
12+
13+
char *ub = lb + size;
14+
size_t offset_ub = __CPROVER_POINTER_OFFSET(ub);
15+
size_t object_ub = __CPROVER_POINTER_OBJECT(ub);
16+
17+
char *ubp1 = lb + size + 1;
18+
size_t offset_ubp1 = __CPROVER_POINTER_OFFSET(ubp1);
19+
size_t object_ubp1 = __CPROVER_POINTER_OBJECT(ubp1);
20+
21+
assert(object_ub == object_lb); // proved
22+
assert(object_ubp1 == object_lb); // proved
23+
assert(ubp1 > ub); // proved
24+
assert(offset_ubp1 > offset_ub); // proved
25+
assert(offset_ubp1 == offset_ub + 1); // falsified
26+
27+
size_t idx;
28+
if(idx < size)
29+
{
30+
char *lb_idx = lb + idx;
31+
void *dummy_ub = ub;
32+
assert(lb <= lb_idx); // proved
33+
assert(lb_idx <= ub); // proved
34+
}
35+
36+
// to produce a trace so that we can observe some intermittent values
37+
assert(size < max_malloc_size);
38+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
main.c
3+
--trace
4+
^\s*ub.*=\(char \*\)&dynamic_object \+ \d+
5+
^\s*offset_ubp1=\d+ul* \(00000000 1[0 ]+1\)$
6+
^VERIFICATION FAILED$
7+
^EXIT=10$
8+
^SIGNAL=0$
9+
--
10+
^warning: ignoring
11+
^\s*ub.*=\(char \*\)&dynamic_object \+ -\d+
12+
^\s*offset_ubp1=\d+ul* \(11111111 1
13+
--
14+
Verifies that all offsets use unsigned arithmetic.

regression/contracts-dfcc/memory-predicates-is-fresh-failure-modes/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ __CPROVER_assigns(__CPROVER_object_from(arr))
77
// clang-format on
88
{
99
__CPROVER_assert(arr != NULL, "arr is not NULL");
10-
__CPROVER_assert(size < __CPROVER_max_malloc_size, "size is capped");
11-
if(size > 0)
10+
__CPROVER_assert(size <= __CPROVER_max_malloc_size, "size is capped");
11+
if(size > 0 && size <= __CPROVER_max_malloc_size)
1212
{
1313
arr[0] = 0;
1414
arr[size - 1] = 0;

0 commit comments

Comments
 (0)