Skip to content

Commit 2e2b1a4

Browse files
committed
Refactor allocate_dynamic_object into two functions
One returns the expression representing the pointer to the newly allocated memory, and the other returns the expression representing the dereferenced pointer.
1 parent ab0f296 commit 2e2b1a4

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/util/allocate_objects.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ symbol_exprt allocate_objectst::allocate_automatic_local_object(
121121
return aux_symbol.symbol_expr();
122122
}
123123

124-
exprt allocate_objectst::allocate_dynamic_object(
124+
exprt allocate_objectst::allocate_dynamic_object_symbol(
125125
code_blockt &output_code,
126126
const exprt &target_expr,
127127
const typet &allocate_type)
@@ -165,7 +165,16 @@ exprt allocate_objectst::allocate_dynamic_object(
165165
code.add_source_location() = source_location;
166166
output_code.add(code);
167167

168-
return dereference_exprt(malloc_sym.symbol_expr());
168+
return malloc_sym.symbol_expr();
169+
}
170+
171+
exprt allocate_objectst::allocate_dynamic_object(
172+
code_blockt &output_code,
173+
const exprt &target_expr,
174+
const typet &allocate_type)
175+
{
176+
return dereference_exprt(
177+
allocate_dynamic_object_symbol(output_code, target_expr, allocate_type));
169178
}
170179

171180
exprt allocate_objectst::allocate_non_dynamic_object(

src/util/allocate_objects.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,20 @@ class allocate_objectst
7171
/// `alloc_site$1 = ALLOCATE(object_size, FALSE);`
7272
/// `*p = alloc_site$1;`
7373
///
74-
/// The function returns a dereference expressiont that dereferences the
75-
/// allocation site variable (e.g., `*alloc_site$1`) and which can be used to
76-
/// initialize the allocated memory.
77-
///
7874
/// \param output_code: Code block to which the necessary code is added
7975
/// \param target_expr: A pointer to the allocated memory will be assigned to
8076
/// this (lvalue) expression
8177
/// \param allocate_type: Type of the object allocated
82-
/// \return A dereference_exprt that dereferences the pointer to the allocated
83-
/// memory, or an empty expression when `allocate_type` is void
78+
/// \return The pointer to the allocated memory, or an empty expression
79+
/// when `allocate_type` is void
80+
exprt allocate_dynamic_object_symbol(
81+
code_blockt &output_code,
82+
const exprt &target_expr,
83+
const typet &allocate_type);
84+
85+
/// Generate the same code as \ref allocate_dynamic_object_symbol, but
86+
/// return a dereference_exprt that dereferences the newly created pointer
87+
/// to the allocated memory.
8488
exprt allocate_dynamic_object(
8589
code_blockt &output_code,
8690
const exprt &target_expr,

0 commit comments

Comments
 (0)