Skip to content

Commit 113bcdd

Browse files
committed
Remove __CPROVER_malloc_object
Its use was deprecated since 2021-05-06. The only remaining need for tracking this object is to distinguish new vs new[] (and delete vs delete[]). This specific case is now handled via __CPROVER_new_object.
1 parent 8aab2e5 commit 113bcdd

File tree

16 files changed

+29
-88
lines changed

16 files changed

+29
-88
lines changed

doc/architectural/memory-bounds-checking.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,10 @@ inline void *malloc(__CPROVER_size_t malloc_size)
3030
{
3131
void *malloc_res;
3232
malloc_res = __CPROVER_allocate(malloc_size, 0);
33-
34-
__CPROVER_bool record_malloc = __VERIFIER_nondet___CPROVER_bool();
35-
__CPROVER_malloc_object = record_malloc ? malloc_res : __CPROVER_malloc_object;
36-
3733
return malloc_res;
3834
}
3935
```
4036
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.
45-
4637
When the option `--pointer-check` is used, cbmc generates the following
4738
verification condition for each pointer dereference expression (e.g.,
4839
`*pointer`):
@@ -73,8 +64,7 @@ int main()
7364
```
7465

7566
Here the verification condition generated for the pointer dereference should
76-
fail. In the approach outlined above it indeed can, as one can choose true for
77-
`__VERIFIER_nondet___CPROVER_bool()` in the first call
78-
to `malloc()`, and false for `__VERIFIER_nondet___CPROVER_bool()` in the second
79-
call to `malloc()`. Thus, the object address of the first call to
80-
`malloc()` is recorded in `__CPROVER_malloc_object`.
67+
fail: for `p1` in `*p1`, `__CPROVER_POINTER_OFFSET` will evaluate to 1 (owing to
68+
the increment `p1++`, and `__CPROVER_OBJECT_SIZE` will also evaluate to 1.
69+
Consequently, the less-than comparison in the verification condition evaluates
70+
to false.

jbmc/src/java_bytecode/java_bytecode_internal_additions.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,6 @@ void java_internal_additions(symbol_table_baset &dest)
3636
dest.add(symbol);
3737
}
3838

39-
// add __CPROVER_malloc_object
40-
41-
{
42-
symbolt symbol;
43-
symbol.base_name = CPROVER_PREFIX "malloc_object";
44-
symbol.name=CPROVER_PREFIX "malloc_object";
45-
symbol.type = pointer_type(java_void_type());
46-
symbol.mode=ID_C;
47-
symbol.is_lvalue=true;
48-
symbol.is_state_var=true;
49-
symbol.is_thread_local=true;
50-
dest.add(symbol);
51-
}
52-
5339
{
5440
auxiliary_symbolt symbol;
5541
symbol.base_name = INFLIGHT_EXCEPTION_VARIABLE_BASENAME;

regression/goto-analyzer/sensitivity-last-written-locations-arrays/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ main#return_value \(\) -> TOP @ \[1\]
99
__CPROVER_dead_object \(\) -> TOP @ \[5\]
1010
__CPROVER_deallocated \(\) -> TOP @ \[6\]
1111
__CPROVER_malloc_is_new_array \(\) -> FALSE @ \[9\]
12-
__CPROVER_malloc_object \(\) -> TOP @ \[10\]
13-
__CPROVER_memory_leak \(\) -> TOP @ \[12\]
12+
__CPROVER_memory_leak \(\) -> TOP @ \[11\]
13+
__CPROVER_new_object \(\) -> TOP @ \[12\]
1414
__CPROVER_next_thread_key \(\) -> 0ul @ \[14\]
1515
__CPROVER_pipe_count \(\) -> 0u @ \[15\]
1616
__CPROVER_rounding_mode \(\) -> 0 @ \[16\]

regression/goto-analyzer/sensitivity-last-written-locations-pointers/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ main#return_value \(\) -> TOP @ \[1\]
99
__CPROVER_dead_object \(\) -> TOP @ \[5\]
1010
__CPROVER_deallocated \(\) -> TOP @ \[6\]
1111
__CPROVER_malloc_is_new_array \(\) -> FALSE @ \[9\]
12-
__CPROVER_malloc_object \(\) -> TOP @ \[10\]
13-
__CPROVER_memory_leak \(\) -> TOP @ \[12\]
12+
__CPROVER_memory_leak \(\) -> TOP @ \[11\]
13+
__CPROVER_new_object \(\) -> TOP @ \[12\]
1414
__CPROVER_next_thread_key \(\) -> 0ul @ \[14\]
1515
__CPROVER_pipe_count \(\) -> 0u @ \[15\]
1616
__CPROVER_rounding_mode \(\) -> 0 @ \[16\]

regression/goto-analyzer/sensitivity-last-written-locations-structs/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ main#return_value \(\) -> TOP @ \[1\]
99
__CPROVER_dead_object \(\) -> TOP @ \[5\]
1010
__CPROVER_deallocated \(\) -> TOP @ \[6\]
1111
__CPROVER_malloc_is_new_array \(\) -> FALSE @ \[9\]
12-
__CPROVER_malloc_object \(\) -> TOP @ \[10\]
13-
__CPROVER_memory_leak \(\) -> TOP @ \[12\]
12+
__CPROVER_memory_leak \(\) -> TOP @ \[11\]
13+
__CPROVER_new_object \(\) -> TOP @ \[12\]
1414
__CPROVER_next_thread_key \(\) -> 0ul @ \[14\]
1515
__CPROVER_pipe_count \(\) -> 0u @ \[15\]
1616
__CPROVER_rounding_mode \(\) -> 0 @ \[16\]

regression/goto-analyzer/sensitivity-last-written-locations-variables/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ __CPROVER_alloca_object \(\) -> TOP @ \[4\]
88
__CPROVER_dead_object \(\) -> TOP @ \[5\]
99
__CPROVER_deallocated \(\) -> TOP @ \[6\]
1010
__CPROVER_malloc_is_new_array \(\) -> FALSE @ \[9\]
11-
__CPROVER_malloc_object \(\) -> TOP @ \[10\]
12-
__CPROVER_memory_leak \(\) -> TOP @ \[12\]
11+
__CPROVER_memory_leak \(\) -> TOP @ \[11\]
12+
__CPROVER_new_object \(\) -> TOP @ \[12\]
1313
__CPROVER_next_thread_key \(\) -> 0ul @ \[14\]
1414
__CPROVER_pipe_count \(\) -> 0u @ \[15\]
1515
__CPROVER_rounding_mode \(\) -> 0 @ \[16\]

src/analyses/escape_analysis.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ bool escape_domaint::is_tracked(const symbol_exprt &symbol)
1919
const irep_idt &identifier=symbol.get_identifier();
2020
if(
2121
identifier == CPROVER_PREFIX "memory_leak" ||
22-
identifier == CPROVER_PREFIX "malloc_object" ||
2322
identifier == CPROVER_PREFIX "dead_object" ||
2423
identifier == CPROVER_PREFIX "deallocated")
2524
{

src/ansi-c/ansi_c_internal_additions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void ansi_c_internal_additions(std::string &code)
178178
// malloc
179179
"const void *" CPROVER_PREFIX "deallocated=0;\n"
180180
"const void *" CPROVER_PREFIX "dead_object=0;\n"
181-
"const void *" CPROVER_PREFIX "malloc_object=0;\n"
181+
"const void *" CPROVER_PREFIX "new_object=0;\n" // for C++
182182
CPROVER_PREFIX "bool " CPROVER_PREFIX "malloc_is_new_array=0;\n" // for C++
183183
"const void *" CPROVER_PREFIX "memory_leak=0;\n"
184184
"void *" CPROVER_PREFIX "allocate("

src/ansi-c/library/cprover.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Author: Daniel Kroening, [email protected]
1212
typedef __typeof__(sizeof(int)) __CPROVER_size_t;
1313
void *__CPROVER_allocate(__CPROVER_size_t size, __CPROVER_bool zero);
1414
extern const void *__CPROVER_deallocated;
15-
extern const void *__CPROVER_malloc_object;
15+
extern const void *__CPROVER_new_object;
1616
extern _Bool __CPROVER_malloc_is_new_array;
1717
extern const void *__CPROVER_memory_leak;
1818

src/ansi-c/library/stdlib.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ __CPROVER_HIDE:;
111111

112112
// record the object size for non-determistic bounds checking
113113
__CPROVER_bool record_malloc = __VERIFIER_nondet___CPROVER_bool();
114-
__CPROVER_malloc_object =
115-
record_malloc ? malloc_res : __CPROVER_malloc_object;
116114
__CPROVER_malloc_is_new_array =
117115
record_malloc ? 0 : __CPROVER_malloc_is_new_array;
118116

@@ -175,8 +173,6 @@ __CPROVER_HIDE:;
175173

176174
// record the object size for non-determistic bounds checking
177175
__CPROVER_bool record_malloc = __VERIFIER_nondet___CPROVER_bool();
178-
__CPROVER_malloc_object =
179-
record_malloc ? malloc_res : __CPROVER_malloc_object;
180176
__CPROVER_malloc_is_new_array =
181177
record_malloc ? 0 : __CPROVER_malloc_is_new_array;
182178

@@ -207,7 +203,6 @@ inline void *__builtin_alloca(__CPROVER_size_t alloca_size)
207203

208204
// record the object size for non-determistic bounds checking
209205
__CPROVER_bool record_malloc=__VERIFIER_nondet___CPROVER_bool();
210-
__CPROVER_malloc_object=record_malloc?res:__CPROVER_malloc_object;
211206
__CPROVER_malloc_is_new_array=record_malloc?0:__CPROVER_malloc_is_new_array;
212207

213208
// record alloca to detect invalid free
@@ -258,10 +253,9 @@ inline void free(void *ptr)
258253

259254
// catch people who try to use free(...) for stuff
260255
// allocated with new[]
261-
__CPROVER_precondition(ptr==0 ||
262-
__CPROVER_malloc_object!=ptr ||
263-
!__CPROVER_malloc_is_new_array,
264-
"free called for new[] object");
256+
__CPROVER_precondition(
257+
ptr == 0 || __CPROVER_new_object != ptr || !__CPROVER_malloc_is_new_array,
258+
"free called for new[] object");
265259

266260
// catch people who try to use free(...) with alloca
267261
__CPROVER_precondition(

0 commit comments

Comments
 (0)