Skip to content

Commit 804efea

Browse files
authored
Merge pull request #4349 from antlechner/antonia/move_make_allocate_code
Move make_allocate_code utility function
2 parents d91b397 + b2e9778 commit 804efea

File tree

5 files changed

+15
-23
lines changed

5 files changed

+15
-23
lines changed

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,18 +1194,6 @@ void java_object_factoryt::allocate_nondet_length_array(
11941194
assignments.add(assign);
11951195
}
11961196

1197-
/// Create code allocating object of size `size` and assigning it to `lhs`
1198-
/// \param lhs : pointer which will be allocated
1199-
/// \param size : size of the object
1200-
/// \return code allocation object and assigning `lhs`
1201-
codet make_allocate_code(const symbol_exprt &lhs, const exprt &size)
1202-
{
1203-
side_effect_exprt alloc(ID_allocate, lhs.type(), lhs.source_location());
1204-
alloc.add_to_operands(size);
1205-
alloc.add_to_operands(false_exprt());
1206-
return code_assignt(lhs, alloc);
1207-
}
1208-
12091197
/// Create code to nondeterministically initialize arrays of primitive type.
12101198
/// The code produced is of the form (for an array of type TYPE):
12111199
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

jbmc/src/java_bytecode/java_object_factory.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,4 @@ void gen_nondet_init(
126126
const java_object_factory_parameterst &object_factory_parameters,
127127
update_in_placet update_in_place);
128128

129-
codet make_allocate_code(const symbol_exprt &lhs, const exprt &size);
130-
131129
#endif // CPROVER_JAVA_BYTECODE_JAVA_OBJECT_FACTORY_H

jbmc/src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Date: April 2017
2626
#include <util/string_expr.h>
2727

2828
#include "java_types.h"
29-
#include "java_object_factory.h"
3029
#include "java_utils.h"
3130

3231
#include "java_string_library_preprocess.h"

src/util/allocate_objects.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,6 @@ exprt allocate_objectst::allocate_dynamic_object(
159159
auto object_size = size_of_expr(allocate_type, ns);
160160
INVARIANT(object_size.has_value(), "Size of objects should be known");
161161

162-
// malloc expression
163-
side_effect_exprt malloc_expr(
164-
ID_allocate, pointer_type(allocate_type), source_location);
165-
malloc_expr.copy_to_operands(object_size.value());
166-
malloc_expr.copy_to_operands(false_exprt());
167-
168162
// create a symbol for the malloc expression so we can initialize
169163
// without having to do it potentially through a double-deref, which
170164
// breaks the to-SSA phase.
@@ -178,8 +172,8 @@ exprt allocate_objectst::allocate_dynamic_object(
178172

179173
symbols_created.push_back(&malloc_sym);
180174

181-
code_assignt assign(malloc_sym.symbol_expr(), malloc_expr);
182-
assign.add_source_location() = source_location;
175+
code_assignt assign =
176+
make_allocate_code(malloc_sym.symbol_expr(), object_size.value());
183177
output_code.add(assign);
184178

185179
exprt malloc_symbol_expr = typecast_exprt::conditional_cast(
@@ -271,3 +265,10 @@ void allocate_objectst::mark_created_symbols_as_input(code_blockt &init_code)
271265
init_code.add(std::move(input_code));
272266
}
273267
}
268+
269+
code_assignt make_allocate_code(const symbol_exprt &lhs, const exprt &size)
270+
{
271+
side_effect_exprt alloc{
272+
ID_allocate, {size, false_exprt()}, lhs.type(), lhs.source_location()};
273+
return code_assignt(lhs, alloc);
274+
}

src/util/allocate_objects.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,10 @@ class allocate_objectst
9595
const irep_idt &basename_prefix);
9696
};
9797

98+
/// Create code allocating an object of size `size` and assigning it to `lhs`
99+
/// \param lhs: pointer which will be allocated
100+
/// \param size: size of the object
101+
/// \return code allocating the object and assigning it to `lhs`
102+
code_assignt make_allocate_code(const symbol_exprt &lhs, const exprt &size);
103+
98104
#endif // CPROVER_UTIL_ALLOCATE_OBJECTS_H

0 commit comments

Comments
 (0)