CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
new.c
Go to the documentation of this file.
1/* FUNCTION: __new */
2
4const void *__CPROVER_new_object = 0;
6
7inline void *__new(__typeof__(sizeof(int)) malloc_size)
8{
9 // The constructor call is done by the front-end.
10 // This just does memory allocation.
12 void *res;
14
15 // non-deterministically record the object for delete/delete[] checking
19
20 // detect memory leaks
23
24 return res;
25}
26
27/* FUNCTION: __new_array */
28
30#ifndef LIBRARY_CHECK
31const void *__CPROVER_new_object = 0;
33#endif
34
36{
37 // The constructor call is done by the front-end.
38 // This just does memory allocation.
40 void *res;
41 res = __CPROVER_allocate(size*count, 0);
42
43 // non-deterministically record the object for delete/delete[] checking
47
48 // detect memory leaks
51
52 return res;
53}
54
55/* FUNCTION: __placement_new */
56
57inline void *__placement_new(__typeof__(sizeof(int)) malloc_size, void *p)
58{
59 // The constructor call is done by the front-end.
60 // The allocation is done by the user. So this does nothing.
63 return p;
64}
65
66/* FUNCTION: __delete */
67
68void __CPROVER_deallocate(void *);
70#ifndef LIBRARY_CHECK
71const void *__CPROVER_new_object = 0;
73#endif
74
75inline void __delete(void *ptr)
76{
78 // is it dynamic?
80 "delete argument must be dynamic object");
82 "delete argument must have offset zero");
83
84 // catch double delete
85 __CPROVER_precondition(ptr==0 || __CPROVER_deallocated!=ptr, "double delete");
86
87 // catch people who call delete for objects allocated with new[]
90 "delete of array object");
91
92 // If ptr is NULL, no operation is performed.
93 // This is a requirement by the standard, not generosity!
94 if(ptr!=0)
95 {
97
98 // detect memory leaks
101 }
102}
103
104/* FUNCTION: __delete_array */
105
106void __CPROVER_deallocate(void *);
108#ifndef LIBRARY_CHECK
109const void *__CPROVER_new_object = 0;
111#endif
112
113inline void __delete_array(void *ptr)
114{
116 // If ptr is NULL, no operation is performed.
117 // This is a requirement by the standard, not generosity!
118
119 // is it dynamic?
121 "delete argument must be dynamic object");
123 "delete argument must have offset zero");
124
125 // catch double delete
127 "double delete");
128
129 // catch people who call delete[] for objects allocated with new
132 "delete[] of non-array object");
133
134 if(ptr!=0)
135 {
137
138 // detect memory leaks
140 }
141}
typedef __typeof__(sizeof(int)) __CPROVER_size_t
void * __CPROVER_allocate(__CPROVER_size_t size, __CPROVER_bool zero)
const void * __CPROVER_deallocated
const void * __CPROVER_memory_leak
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
__CPROVER_size_t __CPROVER_POINTER_OFFSET(const void *)
void __CPROVER_precondition(__CPROVER_bool precondition, const char *description)
__CPROVER_bool __CPROVER_DYNAMIC_OBJECT(const void *)
void __delete(void *ptr)
Definition new.c:75
void * __new(__typeof__(sizeof(int)) malloc_size)
Definition new.c:7
void __delete_array(void *ptr)
Definition new.c:113
void * __new_array(__CPROVER_size_t count, __CPROVER_size_t size)
Definition new.c:35
void __CPROVER_deallocate(void *)
Definition stdlib.c:670
const void * __CPROVER_new_object
Definition new.c:4
__CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void)
__CPROVER_bool __CPROVER_malloc_is_new_array
Definition new.c:5
void * __placement_new(__typeof__(sizeof(int)) malloc_size, void *p)
Definition new.c:57