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