Skip to content

Commit 44618e9

Browse files
author
svorenova
committed
clinit_wrapper cont. (to be squashed later)
Instead of nondet-initializing all static variables instead of calling clinit, call clinit and then nondet-initialize all non-final static variables (to make sure they get the correct value from the clinit)
1 parent 372ebcc commit 44618e9

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

jbmc/src/java_bytecode/java_static_initializers.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ gen_clinit_eqexpr(const exprt &expr, const clinit_statest state)
180180

181181
/// Generates codet that iterates through the base types of the class specified
182182
/// by class_name, C, and recursively adds calls to their clinit wrapper.
183-
/// Finally a call to the clinit of C is made or if nondet-static option was
184-
/// given then all static variables of the class are nondet-initialized instead.
183+
/// Finally a call to the clinit of C is made. If nondet-static option was
184+
/// given then all static variables that are not constants (i.e. final) are
185+
/// then re-assigned to a nondet value.
185186
/// \param symbol_table: symbol table
186187
/// \param class_name: name of the class to generate clinit wrapper calls for
187188
/// \param [out] init_body: appended with calls to clinit wrapper
@@ -216,26 +217,24 @@ static void clinit_wrapper_do_recursive_calls(
216217
auto find_sym_it = symbol_table.symbols.find(real_clinit_name);
217218
if(find_sym_it != symbol_table.symbols.end())
218219
{
219-
if(!nondet_static)
220+
code_function_callt call_real_init;
221+
call_real_init.function() = find_sym_it->second.symbol_expr();
222+
init_body.move_to_operands(call_real_init);
223+
224+
// Add a standard nondet initialisation for each global declared on this
225+
// class. Note this is the same invocation used in
226+
// get_stub_initializer_body and java_static_lifetime_init.
227+
if(nondet_static)
220228
{
221-
code_function_callt call_real_init;
222-
call_real_init.function() = find_sym_it->second.symbol_expr();
223-
init_body.move_to_operands(call_real_init);
224-
}
225-
else
226-
{
227-
// Add a standard nondet initialisation for each global declared on this
228-
// class. Note this is the same invocation used in
229-
// get_stub_initializer_body and java_static_lifetime_init.
230-
231229
object_factory_parameterst parameters = object_factory_parameters;
232230
parameters.function_id = clinit_wrapper_name(class_name);
233231

234232
for(const auto &symbol : symbol_table.symbols)
235233
{
236234
if(
235+
symbol.second.type.get(ID_C_class) == class_name &&
237236
symbol.second.is_static_lifetime &&
238-
symbol.second.type.get(ID_C_class) == class_name)
237+
!symbol.second.type.get_bool(ID_C_constant))
239238
{
240239
const symbol_exprt new_global_symbol = symbol.second.symbol_expr();
241240

0 commit comments

Comments
 (0)