Skip to content

Commit 912828d

Browse files
committed
JBMC: Run remove-virtual-functions as each function is converted
This means lazy loading drivers do not need to understand virtual function calls, as they have already been converted into explicit dispatch tables.
1 parent a711c64 commit 912828d

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/goto-programs/remove_virtual_functions.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class remove_virtual_functionst
2424
{
2525
public:
2626
remove_virtual_functionst(
27-
const symbol_tablet &_symbol_table,
28-
const goto_functionst &goto_functions);
27+
const symbol_tablet &_symbol_table);
2928

3029
void operator()(goto_functionst &goto_functions);
3130

@@ -65,8 +64,7 @@ class remove_virtual_functionst
6564
};
6665

6766
remove_virtual_functionst::remove_virtual_functionst(
68-
const symbol_tablet &_symbol_table,
69-
const goto_functionst &goto_functions):
67+
const symbol_tablet &_symbol_table):
7068
ns(_symbol_table),
7169
symbol_table(_symbol_table)
7270
{
@@ -436,9 +434,7 @@ void remove_virtual_functions(
436434
const symbol_tablet &symbol_table,
437435
goto_functionst &goto_functions)
438436
{
439-
remove_virtual_functionst
440-
rvf(symbol_table, goto_functions);
441-
437+
remove_virtual_functionst rvf(symbol_table);
442438
rvf(goto_functions);
443439
}
444440

@@ -448,15 +444,24 @@ void remove_virtual_functions(goto_modelt &goto_model)
448444
goto_model.symbol_table, goto_model.goto_functions);
449445
}
450446

447+
void remove_virtual_functions(goto_model_functiont &function)
448+
{
449+
remove_virtual_functionst rvf(function.get_symbol_table());
450+
bool changed = rvf.remove_virtual_functions(
451+
function.get_goto_function().body);
452+
// Give fresh location numbers to `function`, in case it has grown:
453+
if(changed)
454+
function.compute_location_numbers();
455+
}
456+
451457
void remove_virtual_function(
452458
goto_modelt &goto_model,
453459
goto_programt &goto_program,
454460
goto_programt::targett instruction,
455461
const dispatch_table_entriest &dispatch_table,
456462
virtual_dispatch_fallback_actiont fallback_action)
457463
{
458-
remove_virtual_functionst
459-
rvf(goto_model.symbol_table, goto_model.goto_functions);
464+
remove_virtual_functionst rvf(goto_model.symbol_table);
460465

461466
rvf.remove_virtual_function(
462467
goto_program, instruction, dispatch_table, fallback_action);

src/goto-programs/remove_virtual_functions.h

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ void remove_virtual_functions(
2525
const symbol_tablet &symbol_table,
2626
goto_functionst &goto_functions);
2727

28+
/// Remove virtual functions from one function.
29+
/// May change the location numbers in `function`.
30+
/// \param function: function from which virtual functions should be converted
31+
/// to explicit dispatch tables.
32+
void remove_virtual_functions(goto_model_functiont &function);
33+
2834
/// Specifies remove_virtual_function's behaviour when the actual supplied
2935
/// parameter does not match any of the possible callee types
3036
enum class virtual_dispatch_fallback_actiont

src/jbmc/jbmc_parse_options.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,8 @@ void jbmc_parse_optionst::process_goto_function(
648648
remove_asm(goto_function, symbol_table);
649649
// Removal of RTTI inspection:
650650
remove_instanceof(goto_function, symbol_table);
651+
// Java virtual functions -> explicit dispatch tables:
652+
remove_virtual_functions(function);
651653
}
652654

653655
catch(const char *e)
@@ -678,8 +680,6 @@ bool jbmc_parse_optionst::process_goto_functions(
678680
remove_java_new(goto_model, get_message_handler());
679681

680682
status() << "Removal of virtual functions" << eom;
681-
// Java virtual functions -> explicit dispatch tables:
682-
remove_virtual_functions(goto_model);
683683
// remove catch and throw (introduces instanceof but request it is removed)
684684
remove_exceptions(
685685
goto_model, remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF);

0 commit comments

Comments
 (0)