Skip to content

Commit 2dab426

Browse files
authored
Merge pull request #3837 from tautschnig/function-remove_java_new
remove_java_new now takes function identifier [blocks: #3126]
2 parents c98cd43 + 6c48af5 commit 2dab426

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

jbmc/src/java_bytecode/remove_java_new.cpp

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,27 @@ class remove_java_newt : public messaget
3333
}
3434

3535
// Lower java_new for a single function
36-
bool lower_java_new(goto_programt &);
36+
bool lower_java_new(const irep_idt &function_identifier, goto_programt &);
3737

3838
// Lower java_new for a single instruction
39-
goto_programt::targett
40-
lower_java_new(goto_programt &, goto_programt::targett);
39+
goto_programt::targett lower_java_new(
40+
const irep_idt &function_identifier,
41+
goto_programt &,
42+
goto_programt::targett);
4143

4244
protected:
4345
symbol_table_baset &symbol_table;
4446
namespacet ns;
4547

4648
goto_programt::targett lower_java_new(
49+
const irep_idt &function_identifier,
4750
exprt lhs,
4851
side_effect_exprt rhs,
4952
goto_programt &,
5053
goto_programt::targett);
5154

5255
goto_programt::targett lower_java_new_array(
56+
const irep_idt &function_identifier,
5357
exprt lhs,
5458
side_effect_exprt rhs,
5559
goto_programt &,
@@ -60,6 +64,7 @@ class remove_java_newt : public messaget
6064
/// two instructions:
6165
/// lhs = ALLOCATE(java_type)
6266
/// *lhs = { zero-initialized java_type }
67+
/// \param function_identifier: Name of the function containing \p target.
6368
/// \param lhs: the lhs
6469
/// \param rhs: the rhs
6570
/// \param dest: the goto program to modify
@@ -68,6 +73,7 @@ class remove_java_newt : public messaget
6873
/// Note: we have to take a copy of `lhs` and `rhs` since they would suffer
6974
/// destruction when replacing the instruction.
7075
goto_programt::targett remove_java_newt::lower_java_new(
76+
const irep_idt &function_identifier,
7177
exprt lhs,
7278
side_effect_exprt rhs,
7379
goto_programt &dest,
@@ -108,6 +114,7 @@ goto_programt::targett remove_java_newt::lower_java_new(
108114
/// the following code:
109115
/// lhs = ALLOCATE(java_type)
110116
/// loops to initialize the elements (including multi-dimensional arrays)
117+
/// \param function_identifier: Name of the function containing \p target.
111118
/// \param lhs: the lhs
112119
/// \param rhs: the rhs
113120
/// \param dest: the goto program to modify
@@ -116,6 +123,7 @@ goto_programt::targett remove_java_newt::lower_java_new(
116123
/// Note: we have to take a copy of `lhs` and `rhs` since they would suffer
117124
/// destruction when replacing the instruction.
118125
goto_programt::targett remove_java_newt::lower_java_new_array(
126+
const irep_idt &function_identifier,
119127
exprt lhs,
120128
side_effect_exprt rhs,
121129
goto_programt &dest,
@@ -206,7 +214,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
206214
// `x=typecast_exprt(side_effect_exprt(...))`
207215
symbol_exprt new_array_data_symbol = get_fresh_aux_symbol(
208216
data_java_new_expr.type(),
209-
id2string(target->function),
217+
id2string(function_identifier),
210218
"tmp_new_data_array",
211219
location,
212220
ID_java,
@@ -254,7 +262,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
254262

255263
symbol_exprt tmp_i = get_fresh_aux_symbol(
256264
length.type(),
257-
id2string(target->function),
265+
id2string(function_identifier),
258266
"tmp_index",
259267
location,
260268
ID_java,
@@ -286,7 +294,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
286294
code_blockt for_body;
287295
symbol_exprt init_sym = get_fresh_aux_symbol(
288296
sub_type,
289-
id2string(target->function),
297+
id2string(function_identifier),
290298
"subarray_init",
291299
location,
292300
ID_java,
@@ -311,7 +319,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
311319
goto_convert(for_loop, symbol_table, tmp, get_message_handler(), ID_java);
312320

313321
// lower new side effects recursively
314-
lower_java_new(tmp);
322+
lower_java_new(function_identifier, tmp);
315323

316324
dest.destructive_insert(next, tmp);
317325
}
@@ -321,10 +329,12 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
321329

322330
/// Replace every java_new or java_new_array by a malloc side-effect
323331
/// and zero initialization.
332+
/// \param function_identifier: Name of the function containing \p target.
324333
/// \param goto_program: program to process
325334
/// \param target: instruction to check for java_new expressions
326335
/// \return true if a replacement has been made
327336
goto_programt::targett remove_java_newt::lower_java_new(
337+
const irep_idt &function_identifier,
328338
goto_programt &goto_program,
329339
goto_programt::targett target)
330340
{
@@ -338,13 +348,14 @@ goto_programt::targett remove_java_newt::lower_java_new(
338348

339349
if(rhs.id() == ID_side_effect && rhs.get(ID_statement) == ID_java_new)
340350
{
341-
return lower_java_new(lhs, to_side_effect_expr(rhs), goto_program, target);
351+
return lower_java_new(
352+
function_identifier, lhs, to_side_effect_expr(rhs), goto_program, target);
342353
}
343354

344355
if(rhs.id() == ID_side_effect && rhs.get(ID_statement) == ID_java_new_array)
345356
{
346357
return lower_java_new_array(
347-
lhs, to_side_effect_expr(rhs), goto_program, target);
358+
function_identifier, lhs, to_side_effect_expr(rhs), goto_program, target);
348359
}
349360

350361
return target;
@@ -353,17 +364,21 @@ goto_programt::targett remove_java_newt::lower_java_new(
353364
/// Replace every java_new or java_new_array by a malloc side-effect
354365
/// and zero initialization.
355366
/// Extra auxiliary variables may be introduced into symbol_table.
367+
/// \param function_identifier: Name of the function \p goto_program.
356368
/// \param goto_program: The function body to work on.
357369
/// \return true if one or more java_new expressions have been replaced
358-
bool remove_java_newt::lower_java_new(goto_programt &goto_program)
370+
bool remove_java_newt::lower_java_new(
371+
const irep_idt &function_identifier,
372+
goto_programt &goto_program)
359373
{
360374
bool changed = false;
361375
for(goto_programt::instructionst::iterator target =
362376
goto_program.instructions.begin();
363377
target != goto_program.instructions.end();
364378
++target)
365379
{
366-
goto_programt::targett new_target = lower_java_new(goto_program, target);
380+
goto_programt::targett new_target =
381+
lower_java_new(function_identifier, goto_program, target);
367382
changed = changed || new_target == target;
368383
target = new_target;
369384
}
@@ -376,33 +391,37 @@ bool remove_java_newt::lower_java_new(goto_programt &goto_program)
376391
/// Replace every java_new or java_new_array by a malloc side-effect
377392
/// and zero initialization.
378393
/// \remarks Extra auxiliary variables may be introduced into symbol_table.
394+
/// \param function_identifier: Name of the function containing \p target.
379395
/// \param target: The instruction to work on.
380396
/// \param goto_program: The function body containing the instruction.
381397
/// \param symbol_table: The symbol table to add symbols to.
382398
/// \param message_handler: a message handler
383399
void remove_java_new(
400+
const irep_idt &function_identifier,
384401
goto_programt::targett target,
385402
goto_programt &goto_program,
386403
symbol_table_baset &symbol_table,
387404
message_handlert &message_handler)
388405
{
389406
remove_java_newt rem(symbol_table, message_handler);
390-
rem.lower_java_new(goto_program, target);
407+
rem.lower_java_new(function_identifier, goto_program, target);
391408
}
392409

393410
/// Replace every java_new or java_new_array by a malloc side-effect
394411
/// and zero initialization.
395412
/// \remarks Extra auxiliary variables may be introduced into symbol_table.
413+
/// \param function_identifier: Name of the function \p function.
396414
/// \param function: The function to work on.
397415
/// \param symbol_table: The symbol table to add symbols to.
398416
/// \param message_handler: a message handler
399417
void remove_java_new(
418+
const irep_idt &function_identifier,
400419
goto_functionst::goto_functiont &function,
401420
symbol_table_baset &symbol_table,
402421
message_handlert &message_handler)
403422
{
404423
remove_java_newt rem(symbol_table, message_handler);
405-
rem.lower_java_new(function.body);
424+
rem.lower_java_new(function_identifier, function.body);
406425
}
407426

408427
/// Replace every java_new or java_new_array by a malloc side-effect
@@ -419,7 +438,7 @@ void remove_java_new(
419438
remove_java_newt rem(symbol_table, message_handler);
420439
bool changed = false;
421440
for(auto &f : goto_functions.function_map)
422-
changed = rem.lower_java_new(f.second.body) || changed;
441+
changed = rem.lower_java_new(f.first, f.second.body) || changed;
423442
if(changed)
424443
goto_functions.compute_location_numbers();
425444
}

jbmc/src/java_bytecode/remove_java_new.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ Author: Peter Schrammel
2020
class message_handlert;
2121

2222
void remove_java_new(
23+
const irep_idt &function_identifier,
2324
goto_programt::targett target,
2425
goto_programt &goto_program,
2526
symbol_table_baset &symbol_table,
2627
message_handlert &_message_handler);
2728

2829
void remove_java_new(
30+
const irep_idt &function_identifier,
2931
goto_functionst::goto_functiont &function,
3032
symbol_table_baset &symbol_table,
3133
message_handlert &_message_handler);

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,11 @@ void jbmc_parse_optionst::process_goto_function(
811811
function.get_function_id(), function.get_goto_function(), ns, options);
812812

813813
// Replace Java new side effects
814-
remove_java_new(goto_function, symbol_table, get_message_handler());
814+
remove_java_new(
815+
function.get_function_id(),
816+
goto_function,
817+
symbol_table,
818+
get_message_handler());
815819

816820
// checks don't know about adjusted float expressions
817821
adjust_float_expressions(goto_function, ns);

0 commit comments

Comments
 (0)