Skip to content

Commit 732874c

Browse files
Assign string at malloc site
This is much more efficient than assigning to the object in the case the object is an element of an array.
1 parent 768e8a6 commit 732874c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/java_bytecode/java_object_factory.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ exprt allocate_dynamic_object(
248248
/// \param symbol_table: symbol table
249249
/// \param loc: location in the source
250250
/// \param output_code: code block to which the necessary code is added
251-
void allocate_dynamic_object_with_decl(
251+
/// \return the dynamic object created
252+
exprt allocate_dynamic_object_with_decl(
252253
const exprt &target_expr,
253254
symbol_table_baset &symbol_table,
254255
const source_locationt &loc,
@@ -258,7 +259,7 @@ void allocate_dynamic_object_with_decl(
258259
code_blockt tmp_block;
259260
const typet &allocate_type=target_expr.type().subtype();
260261
// We will not use the malloc site and can safely ignore it
261-
(void) allocate_dynamic_object(
262+
const exprt result = allocate_dynamic_object(
262263
target_expr,
263264
allocate_type,
264265
symbol_table,
@@ -278,6 +279,7 @@ void allocate_dynamic_object_with_decl(
278279

279280
for(const exprt &code : tmp_block.operands())
280281
output_code.add(to_code(code));
282+
return result;
281283
}
282284

283285
/// Installs a new symbol in the symbol table, pushing the corresponding symbolt
@@ -701,11 +703,12 @@ static bool add_nondet_string_pointer_initialization(
701703
if(!struct_type.has_component("data") || !struct_type.has_component("length"))
702704
return true;
703705

704-
allocate_dynamic_object_with_decl(expr, symbol_table, loc, code);
706+
const exprt malloc_site =
707+
allocate_dynamic_object_with_decl(expr, symbol_table, loc, code);
705708

706709
code.add(
707710
initialize_nondet_string_struct(
708-
dereference_exprt(expr, struct_type),
711+
dereference_exprt(malloc_site, struct_type),
709712
max_nondet_string_length,
710713
loc,
711714
symbol_table,

src/java_bytecode/java_object_factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ exprt allocate_dynamic_object(
146146
std::vector<const symbolt *> &symbols_created,
147147
bool cast_needed = false);
148148

149-
void allocate_dynamic_object_with_decl(
149+
exprt allocate_dynamic_object_with_decl(
150150
const exprt &target_expr,
151151
symbol_table_baset &symbol_table,
152152
const source_locationt &loc,

0 commit comments

Comments
 (0)