File tree 5 files changed +43
-28
lines changed 5 files changed +43
-28
lines changed Original file line number Diff line number Diff line change @@ -155,12 +155,6 @@ void ansi_c_internal_additions(std::string &code)
155
155
" void *" CPROVER_PREFIX " allocate("
156
156
CPROVER_PREFIX " size_t size, " CPROVER_PREFIX " bool zero);\n "
157
157
" const void *" CPROVER_PREFIX " alloca_object = 0;\n "
158
- " int " CPROVER_PREFIX " malloc_failure_mode=" +
159
- std::to_string (config.ansi_c .malloc_failure_mode )+" ;\n "
160
- " int " CPROVER_PREFIX " malloc_failure_mode_return_null=" +
161
- std::to_string (config.ansi_c .malloc_failure_mode_return_null )+" ;\n "
162
- " int " CPROVER_PREFIX " malloc_failure_mode_assert_then_assume=" +
163
- std::to_string (config.ansi_c .malloc_failure_mode_assert_then_assume )+" ;\n "
164
158
CPROVER_PREFIX " size_t " CPROVER_PREFIX " max_malloc_size=" +
165
159
std::to_string (1 << (config.ansi_c .pointer_width -
166
160
config.bv_encoding .object_bits - 1 ))+" ;\n "
Original file line number Diff line number Diff line change @@ -27,6 +27,21 @@ static std::string get_cprover_library_text(
27
27
if (config.ansi_c .string_abstraction )
28
28
library_text << " #define " CPROVER_PREFIX " STRING_ABSTRACTION\n " ;
29
29
30
+ if (
31
+ config.ansi_c .malloc_failure_mode ==
32
+ config.ansi_c .malloc_failure_mode_return_null )
33
+ {
34
+ library_text << " #define " CPROVER_PREFIX
35
+ " MALLOC_FAILURE_MODE_RETURN_NULL\n " ;
36
+ }
37
+ if (
38
+ config.ansi_c .malloc_failure_mode ==
39
+ config.ansi_c .malloc_failure_mode_assert_then_assume )
40
+ {
41
+ library_text << " #define " CPROVER_PREFIX
42
+ " MALLOC_FAILURE_MODE_ASSERT_THEN_ASSUME\n " ;
43
+ }
44
+
30
45
// cprover_library.inc may not have been generated when running Doxygen, thus
31
46
// make Doxygen skip this part
32
47
// / \cond
@@ -45,7 +60,7 @@ std::string get_cprover_library_text(
45
60
const struct cprover_library_entryt cprover_library[],
46
61
const std::string &prologue)
47
62
{
48
- std::ostringstream library_text ( prologue) ;
63
+ std::ostringstream library_text{ prologue, std::ios_base::ate} ;
49
64
50
65
std::size_t count=0 ;
51
66
Original file line number Diff line number Diff line change @@ -16,13 +16,8 @@ extern const void *__CPROVER_malloc_object;
16
16
extern __CPROVER_size_t __CPROVER_malloc_size ;
17
17
extern _Bool __CPROVER_malloc_is_new_array ;
18
18
extern const void * __CPROVER_memory_leak ;
19
- extern int __CPROVER_malloc_failure_mode ;
20
19
extern __CPROVER_size_t __CPROVER_max_malloc_size ;
21
20
22
- // malloc failure modes
23
- extern int __CPROVER_malloc_failure_mode_return_null ;
24
- extern int __CPROVER_malloc_failure_mode_assert_then_assume ;
25
-
26
21
void __CPROVER_assume (__CPROVER_bool assumption ) __attribute__((__noreturn__ ));
27
22
void __CPROVER_assert (__CPROVER_bool assertion , const char * description );
28
23
void __CPROVER_precondition (__CPROVER_bool assertion , const char * description );
Original file line number Diff line number Diff line change @@ -116,24 +116,17 @@ inline void *malloc(__CPROVER_size_t malloc_size)
116
116
// and __CPROVER_allocate doesn't, but no one cares
117
117
__CPROVER_HIDE :;
118
118
119
- if (
120
- __CPROVER_malloc_failure_mode ==
121
- __CPROVER_malloc_failure_mode_return_null )
119
+ #ifdef __CPROVER_MALLOC_FAILURE_MODE_RETURN_NULL
120
+ if (malloc_size > __CPROVER_max_malloc_size )
122
121
{
123
- if (malloc_size > __CPROVER_max_malloc_size )
124
- {
125
- return (void * )0 ;
126
- }
127
- }
128
- else if (
129
- __CPROVER_malloc_failure_mode ==
130
- __CPROVER_malloc_failure_mode_assert_then_assume )
131
- {
132
- __CPROVER_assert (
133
- malloc_size <= __CPROVER_max_malloc_size ,
134
- "max allocation size exceeded" );
135
- __CPROVER_assume (malloc_size <= __CPROVER_max_malloc_size );
122
+ return (void * )0 ;
136
123
}
124
+ #endif
125
+ #ifdef __CPROVER_MALLOC_FAILURE_MODE_ASSERT_THEN_ASSUME
126
+ __CPROVER_assert (
127
+ malloc_size <= __CPROVER_max_malloc_size , "max allocation size exceeded" );
128
+ __CPROVER_assume (malloc_size <= __CPROVER_max_malloc_size );
129
+ #endif
137
130
138
131
void * malloc_res ;
139
132
malloc_res = __CPROVER_allocate (malloc_size , 0 );
Original file line number Diff line number Diff line change @@ -23,6 +23,24 @@ static std::string get_cprover_library_text(
23
23
library_text << " #line 1 \" <builtin-library>\"\n "
24
24
<< " #undef inline\n " ;
25
25
26
+ if (config.ansi_c .string_abstraction )
27
+ library_text << " #define " CPROVER_PREFIX " STRING_ABSTRACTION\n " ;
28
+
29
+ if (
30
+ config.ansi_c .malloc_failure_mode ==
31
+ config.ansi_c .malloc_failure_mode_return_null )
32
+ {
33
+ library_text << " #define " CPROVER_PREFIX
34
+ " MALLOC_FAILURE_MODE_RETURN_NULL\n " ;
35
+ }
36
+ if (
37
+ config.ansi_c .malloc_failure_mode ==
38
+ config.ansi_c .malloc_failure_mode_assert_then_assume )
39
+ {
40
+ library_text << " #define " CPROVER_PREFIX
41
+ " MALLOC_FAILURE_MODE_ASSERT_THEN_ASSUME\n " ;
42
+ }
43
+
26
44
// cprover_library.inc may not have been generated when running Doxygen, thus
27
45
// make Doxygen skip this part
28
46
// / \cond
You can’t perform that action at this time.
0 commit comments