Skip to content

Commit 542f7fa

Browse files
committed
Replace clinit with user_specified_clinit if given
If a file containing static values is given, the call to clinit within clinit_wrapper is replaced with a call to the new user_specified_clinit function.
1 parent a5966c3 commit 542f7fa

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,7 @@ bool java_bytecode_languaget::convert_single_method(
10911091
function_id,
10921092
symbol_table,
10931093
nondet_static,
1094+
!static_values_file.empty(),
10941095
object_factory_parameters,
10951096
get_pointer_type_selector(),
10961097
get_message_handler());
@@ -1099,6 +1100,7 @@ bool java_bytecode_languaget::convert_single_method(
10991100
function_id,
11001101
symbol_table,
11011102
nondet_static,
1103+
!static_values_file.empty(),
11021104
object_factory_parameters,
11031105
get_pointer_type_selector(),
11041106
get_message_handler());

jbmc/src/java_bytecode/java_static_initializers.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ gen_clinit_eqexpr(const exprt &expr, const clinit_statest state)
196196
/// \param class_name: name of the class to generate clinit wrapper calls for
197197
/// \param [out] init_body: appended with calls to clinit wrapper
198198
/// \param nondet_static: true if nondet-static option was given
199+
/// \param replace_clinit: true iff calls to clinit are replaced with calls to
200+
/// user_specified_clinit.
199201
/// \param object_factory_parameters: object factory parameters used to populate
200202
/// nondet-initialized globals and objects reachable from them (only needed
201203
/// if nondet-static is true)
@@ -207,6 +209,7 @@ static void clinit_wrapper_do_recursive_calls(
207209
const irep_idt &class_name,
208210
code_blockt &init_body,
209211
const bool nondet_static,
212+
const bool replace_clinit,
210213
const java_object_factory_parameterst &object_factory_parameters,
211214
const select_pointer_typet &pointer_type_selector,
212215
message_handlert &message_handler)
@@ -220,8 +223,10 @@ static void clinit_wrapper_do_recursive_calls(
220223
init_body.add(code_function_callt{base_init_func->symbol_expr()});
221224
}
222225

223-
const irep_idt &real_clinit_name = clinit_function_name(class_name);
224-
if(const auto clinit_func = symbol_table.lookup(real_clinit_name))
226+
const irep_idt &clinit_name = replace_clinit
227+
? user_specified_clinit_name(class_name)
228+
: clinit_function_name(class_name);
229+
if(const auto clinit_func = symbol_table.lookup(clinit_name))
225230
init_body.add(code_function_callt{clinit_func->symbol_expr()});
226231

227232
// If nondet-static option is given, add a standard nondet initialization for
@@ -482,6 +487,8 @@ static void create_clinit_wrapper_symbols(
482487
/// name created by `create_clinit_wrapper_symbols`)
483488
/// \param symbol_table: global symbol table
484489
/// \param nondet_static: true if nondet-static option was given
490+
/// \param replace_clinit: true iff calls to clinit are replaced with calls to
491+
/// user_specified_clinit.
485492
/// \param object_factory_parameters: object factory parameters used to populate
486493
/// nondet-initialized globals and objects reachable from them (only needed
487494
/// if nondet-static is true)
@@ -493,6 +500,7 @@ code_blockt get_thread_safe_clinit_wrapper_body(
493500
const irep_idt &function_id,
494501
symbol_table_baset &symbol_table,
495502
const bool nondet_static,
503+
const bool replace_clinit,
496504
const java_object_factory_parameterst &object_factory_parameters,
497505
const select_pointer_typet &pointer_type_selector,
498506
message_handlert &message_handler)
@@ -645,6 +653,7 @@ code_blockt get_thread_safe_clinit_wrapper_body(
645653
*class_name,
646654
init_body,
647655
nondet_static,
656+
replace_clinit,
648657
object_factory_parameters,
649658
pointer_type_selector,
650659
message_handler);
@@ -674,6 +683,8 @@ code_blockt get_thread_safe_clinit_wrapper_body(
674683
/// name created by `create_clinit_wrapper_symbols`)
675684
/// \param symbol_table: global symbol table
676685
/// \param nondet_static: true if nondet-static option was given
686+
/// \param replace_clinit: true iff calls to clinit are replaced with calls to
687+
/// user_specified_clinit.
677688
/// \param object_factory_parameters: object factory parameters used to populate
678689
/// nondet-initialized globals and objects reachable from them (only needed
679690
/// if nondet-static is true)
@@ -685,6 +696,7 @@ code_ifthenelset get_clinit_wrapper_body(
685696
const irep_idt &function_id,
686697
symbol_table_baset &symbol_table,
687698
const bool nondet_static,
699+
const bool replace_clinit,
688700
const java_object_factory_parameterst &object_factory_parameters,
689701
const select_pointer_typet &pointer_type_selector,
690702
message_handlert &message_handler)
@@ -729,6 +741,7 @@ code_ifthenelset get_clinit_wrapper_body(
729741
*class_name,
730742
init_body,
731743
nondet_static,
744+
replace_clinit,
732745
object_factory_parameters,
733746
pointer_type_selector,
734747
message_handler);

jbmc/src/java_bytecode/java_static_initializers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ code_blockt get_thread_safe_clinit_wrapper_body(
3434
const irep_idt &function_id,
3535
symbol_table_baset &symbol_table,
3636
const bool nondet_static,
37+
const bool replace_clinit,
3738
const java_object_factory_parameterst &object_factory_parameters,
3839
const select_pointer_typet &pointer_type_selector,
3940
message_handlert &message_handler);
@@ -42,6 +43,7 @@ code_ifthenelset get_clinit_wrapper_body(
4243
const irep_idt &function_id,
4344
symbol_table_baset &symbol_table,
4445
const bool nondet_static,
46+
const bool replace_clinit,
4547
const java_object_factory_parameterst &object_factory_parameters,
4648
const select_pointer_typet &pointer_type_selector,
4749
message_handlert &message_handler);

0 commit comments

Comments
 (0)