@@ -180,7 +180,8 @@ gen_clinit_eqexpr(const exprt &expr, const clinit_statest state)
180
180
181
181
// / Generates codet that iterates through the base types of the class specified
182
182
// / by class_name, C, and recursively adds calls to their clinit wrapper.
183
- // / Finally a call to the clinint wrapper of C is made.
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.
184
185
// / \param symbol_table: symbol table
185
186
// / \param class_name: name of the class to generate clinit wrapper calls for
186
187
// / \param [out] init_body: appended with calls to clinit wrapper
@@ -191,7 +192,7 @@ gen_clinit_eqexpr(const exprt &expr, const clinit_statest state)
191
192
// / \param pointer_type_selector: used to choose concrete types for abstract-
192
193
// / typed globals and fields (only needed if nondet-static is true)
193
194
static void clinit_wrapper_do_recursive_calls (
194
- const symbol_tablet &symbol_table,
195
+ symbol_table_baset &symbol_table,
195
196
const irep_idt &class_name,
196
197
code_blockt &init_body,
197
198
const bool nondet_static,
@@ -215,9 +216,48 @@ static void clinit_wrapper_do_recursive_calls(
215
216
auto find_sym_it = symbol_table.symbols .find (real_clinit_name);
216
217
if (find_sym_it != symbol_table.symbols .end ())
217
218
{
218
- code_function_callt call_real_init;
219
- call_real_init.function () = find_sym_it->second .symbol_expr ();
220
- init_body.move_to_operands (call_real_init);
219
+ if (!nondet_static)
220
+ {
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
+
231
+ object_factory_parameterst parameters = object_factory_parameters;
232
+ parameters.function_id = clinit_wrapper_name (class_name);
233
+
234
+ for (const auto &symbol : symbol_table.symbols )
235
+ {
236
+ if (
237
+ symbol.second .is_static_lifetime &&
238
+ symbol.second .type .get (ID_C_class) == class_name)
239
+ {
240
+ const symbol_exprt new_global_symbol = symbol.second .symbol_expr ();
241
+
242
+ parameters.max_nonnull_tree_depth =
243
+ is_non_null_library_global (symbol.first )
244
+ ? std::max (
245
+ size_t (1 ), object_factory_parameters.max_nonnull_tree_depth )
246
+ : object_factory_parameters.max_nonnull_tree_depth ;
247
+
248
+ gen_nondet_init (
249
+ new_global_symbol,
250
+ init_body,
251
+ symbol_table,
252
+ source_locationt (),
253
+ false ,
254
+ allocation_typet::DYNAMIC,
255
+ parameters,
256
+ pointer_type_selector,
257
+ update_in_placet::NO_UPDATE_IN_PLACE);
258
+ }
259
+ }
260
+ }
221
261
}
222
262
}
223
263
@@ -374,7 +414,8 @@ static void create_clinit_wrapper_symbols(
374
414
// / // ...
375
415
// / java::In::clinit_wrapper();
376
416
// /
377
- // / java::C::<clinit>();
417
+ // / java::C::<clinit>(); // or nondet-initialization of all static
418
+ // / // variables of C if nondet-static is true
378
419
// /
379
420
// / // Setting this variable to INIT_COMPLETE will let other threads "cross"
380
421
// / // beyond the assume() statement above in this function.
@@ -550,7 +591,8 @@ codet get_thread_safe_clinit_wrapper_body(
550
591
// // ...
551
592
// java::In::clinit_wrapper();
552
593
//
553
- // java::C::<clinit>();
594
+ // java::C::<clinit>(); // or nondet-initialization of all static
595
+ // // variables of C if nondet-static is true
554
596
//
555
597
{
556
598
code_blockt init_body;
@@ -616,7 +658,8 @@ codet get_clinit_wrapper_body(
616
658
// // ...
617
659
// java::In::clinit_wrapper();
618
660
//
619
- // java::C::<clinit>();
661
+ // java::C::<clinit>(); // or nondet-initialization of all static
662
+ // // variables of C if nondet-static is true
620
663
// }
621
664
// }
622
665
const symbolt &wrapper_method_symbol = symbol_table.lookup_ref (function_id);
0 commit comments