Skip to content

Commit eddc014

Browse files
authored
Merge pull request #6086 from tautschnig/remove-malloc_size
Remove __CPROVER_malloc_size
2 parents 43c04ab + 9501bed commit eddc014

File tree

39 files changed

+212
-294
lines changed

39 files changed

+212
-294
lines changed

doc/architectural/memory-bounds-checking.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,27 @@ inline void *malloc(__CPROVER_size_t malloc_size)
3333

3434
__CPROVER_bool record_malloc = __VERIFIER_nondet___CPROVER_bool();
3535
__CPROVER_malloc_object = record_malloc ? malloc_res : __CPROVER_malloc_object;
36-
__CPROVER_malloc_size = record_malloc ? malloc_size : __CPROVER_malloc_size;
3736

3837
return malloc_res;
3938
}
4039
```
4140
42-
Both internal variables `__CPROVER_malloc_object` and `__CPROVER_malloc_size`
43-
are initialized to 0 in the `__CPROVER_initialize()` function of a goto program.
44-
The nondeterministic switch controls whether the address and size of the memory
45-
block allocated in this particular invocation of `malloc()` are recorded.
41+
The internal variable `__CPROVER_malloc_object`
42+
is initialized to 0 in the `__CPROVER_initialize()` function of a goto program.
43+
The nondeterministic switch controls whether the address of the memory
44+
block allocated in this particular invocation of `malloc()` is recorded.
4645
4746
When the option `--pointer-check` is used, cbmc generates the following
4847
verification condition for each pointer dereference expression (e.g.,
4948
`*pointer`):
5049
5150
```C
52-
__CPROVER_POINTER_OBJECT(pointer) == __CPROVER_POINTER_OBJECT(__CPROVER_malloc_object) ==>
53-
__CPROVER_POINTER_OFFSET(pointer) >= 0 && __CPROVER_POINTER_OFFSET(pointer) < __CPROVER_malloc_size
51+
__CPROVER_POINTER_OFFSET(pointer) >= 0 &&
52+
__CPROVER_POINTER_OFFSET(pointer) < __CPROVER_OBJECT_SIZE(pointer)
5453
```
5554

56-
The primitives `__CPROVER_POINTER_OBJECT()` and `__CPROVER_POINTER_OFFSET()` extract
57-
the object id, and pointer offset, respectively. Similar conditions are
55+
The primitives `__CPROVER_POINTER_OFFSET()` and `__CPROVER_OBJECT_SIZE()` extract
56+
the pointer offset and size of the object pointed to, respectively. Similar conditions are
5857
generated for `assert(__CPROVER_r_ok(pointer, size))` and
5958
`assert(__CPROVER_w_ok(pointer, size))`.
6059

@@ -77,9 +76,5 @@ Here the verification condition generated for the pointer dereference should
7776
fail. In the approach outlined above it indeed can, as one can choose true for
7877
`__VERIFIER_nondet___CPROVER_bool()` in the first call
7978
to `malloc()`, and false for `__VERIFIER_nondet___CPROVER_bool()` in the second
80-
call to `malloc()`. Thus, the object address and size of the first call to
81-
`malloc()` are recorded in `__CPROVER_malloc_object` and `__CPROVER_malloc_size`
82-
respectively. Thus, the premise of the implication in the verification condition
83-
above is true, while the conclusion is false, hence the overall condition is
84-
false.
85-
79+
call to `malloc()`. Thus, the object address of the first call to
80+
`malloc()` is recorded in `__CPROVER_malloc_object`.

regression/cbmc-with-incr/Pointer_byte_extract8/main.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ typedef struct
1212
Union List[1];
1313
} __attribute__((packed)) Struct3;
1414

15-
extern size_t __CPROVER_malloc_size;
16-
1715
int main()
1816
{
1917
Struct3 *p = malloc (sizeof (int) + 2 * sizeof(Union));
2018
p->Count = 3;
2119
int po=0;
22-
size_t m=__CPROVER_malloc_size;
2320

2421
// this should be fine
2522
p->List[0].a = 555;

regression/contracts/function_check_mem_01/main.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,16 @@
77

88
#include <stddef.h>
99

10-
#define __CPROVER_VALID_MEM(ptr, size) \
11-
__CPROVER_POINTER_OBJECT((ptr)) != __CPROVER_POINTER_OBJECT(NULL) && \
12-
!__CPROVER_invalid_pointer((ptr)) && \
13-
__CPROVER_POINTER_OBJECT((ptr)) != \
14-
__CPROVER_POINTER_OBJECT(__CPROVER_deallocated) && \
15-
__CPROVER_POINTER_OBJECT((ptr)) != \
16-
__CPROVER_POINTER_OBJECT(__CPROVER_dead_object) && \
17-
(__builtin_object_size((ptr), 1) >= (size) && \
18-
__CPROVER_POINTER_OFFSET((ptr)) >= 0l || \
19-
__CPROVER_DYNAMIC_OBJECT((ptr))) && \
20-
(__CPROVER_POINTER_OFFSET((ptr)) >= 0 && \
21-
__CPROVER_malloc_size >= (size) + __CPROVER_POINTER_OFFSET((ptr)) || \
22-
__CPROVER_POINTER_OBJECT((ptr)) != \
23-
__CPROVER_POINTER_OBJECT(__CPROVER_malloc_object))
24-
10+
#define __CPROVER_VALID_MEM(ptr, size) \
11+
__CPROVER_POINTER_OBJECT((ptr)) != __CPROVER_POINTER_OBJECT(NULL) && \
12+
!__CPROVER_invalid_pointer((ptr)) && \
13+
__CPROVER_POINTER_OBJECT((ptr)) != \
14+
__CPROVER_POINTER_OBJECT(__CPROVER_deallocated) && \
15+
__CPROVER_POINTER_OBJECT((ptr)) != \
16+
__CPROVER_POINTER_OBJECT(__CPROVER_dead_object) && \
17+
(__builtin_object_size((ptr), 1) >= (size) && \
18+
__CPROVER_POINTER_OFFSET((ptr)) >= 0l)
19+
2520
typedef struct bar
2621
{
2722
int x;

regression/goto-analyzer/constant_propagation_01/test-vsd.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ main.c
44
^EXIT=0$
55
^SIGNAL=0$
66
^Simplified: assert: 1, assume: 0, goto: 1, assigns: 7, function calls: 0$
7-
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 17, function calls: 2$
7+
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 16, function calls: 2$
88
--
99
^warning: ignoring

regression/goto-analyzer/constant_propagation_01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ main.c
44
^EXIT=0$
55
^SIGNAL=0$
66
^Simplified: assert: 1, assume: 0, goto: 1, assigns: 7, function calls: 0$
7-
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 17, function calls: 2$
7+
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 16, function calls: 2$
88
--
99
^warning: ignoring

regression/goto-analyzer/constant_propagation_02/test-vsd.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ main.c
44
^EXIT=0$
55
^SIGNAL=0$
66
^Simplified: assert: 1, assume: 0, goto: 1, assigns: 8, function calls: 0$
7-
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 16, function calls: 2$
7+
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 15, function calls: 2$
88
--
99
^warning: ignoring

regression/goto-analyzer/constant_propagation_02/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ main.c
44
^EXIT=0$
55
^SIGNAL=0$
66
^Simplified: assert: 1, assume: 0, goto: 1, assigns: 8, function calls: 0$
7-
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 16, function calls: 2$
7+
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 15, function calls: 2$
88
--
99
^warning: ignoring

regression/goto-analyzer/constant_propagation_03/test-vsd.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ main.c
44
^EXIT=0$
55
^SIGNAL=0$
66
^Simplified: assert: 1, assume: 0, goto: 1, assigns: 8, function calls: 0$
7-
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 16, function calls: 2$
7+
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 15, function calls: 2$
88
--
99
^warning: ignoring

regression/goto-analyzer/constant_propagation_03/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ main.c
44
^EXIT=0$
55
^SIGNAL=0$
66
^Simplified: assert: 1, assume: 0, goto: 1, assigns: 8, function calls: 0$
7-
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 16, function calls: 2$
7+
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 15, function calls: 2$
88
--
99
^warning: ignoring

regression/goto-analyzer/constant_propagation_04/test-vsd.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ main.c
44
^EXIT=0$
55
^SIGNAL=0$
66
^Simplified: assert: 1, assume: 0, goto: 1, assigns: 8, function calls: 0$
7-
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 16, function calls: 2$
7+
^Unmodified: assert: 0, assume: 0, goto: 0, assigns: 15, function calls: 2$
88
--
99
^warning: ignoring

0 commit comments

Comments
 (0)