@@ -473,6 +473,8 @@ void java_object_factoryt::gen_nondet_pointer_init(
473
473
alloc_type,
474
474
update_in_placet::NO_UPDATE_IN_PLACE);
475
475
476
+ auto set_null_inst=get_null_assignment (expr, pointer_type);
477
+
476
478
// Determine whether the pointer can be null.
477
479
// In particular the array field of a String should not be null.
478
480
bool not_null=
@@ -483,7 +485,18 @@ void java_object_factoryt::gen_nondet_pointer_init(
483
485
class_identifier==" java.lang.CharSequence" ) &&
484
486
subtype.id ()==ID_array);
485
487
486
- if (not_null)
488
+ // Alternatively, if this is a void* we *must* initialise with null:
489
+ // (This can currently happen for some cases of #exception_value)
490
+ bool must_be_null=
491
+ subtype==empty_typet ();
492
+
493
+ if (must_be_null)
494
+ {
495
+ // Add the following code to assignments:
496
+ // <expr> = nullptr;
497
+ new_object_assignments.add (set_null_inst);
498
+ }
499
+ else if (not_null)
487
500
{
488
501
// Add the following code to assignments:
489
502
// <expr> = <aoe>;
@@ -500,8 +513,6 @@ void java_object_factoryt::gen_nondet_pointer_init(
500
513
// <code from recursive call to gen_nondet_init() with
501
514
// tmp$<temporary_counter>>
502
515
// }
503
- auto set_null_inst=get_null_assignment (expr, pointer_type);
504
-
505
516
code_ifthenelset null_check;
506
517
null_check.cond ()=side_effect_expr_nondett (bool_typet ());
507
518
null_check.then_case ()=set_null_inst;
@@ -900,6 +911,29 @@ void java_object_factoryt::gen_nondet_array_init(
900
911
assignments.move_to_operands (init_done_label);
901
912
}
902
913
914
+ // / Add code_declt instructions to `init_code` for every non-static symbol
915
+ // / in `symbols_created`
916
+ // / \param symbols_created: list of symbols
917
+ // / \param loc: source location for new code_declt instances
918
+ // / \param [out] init_code: gets code_declt for each symbol
919
+ static void declare_created_symbols (
920
+ const std::vector<const symbolt *> &symbols_created,
921
+ const source_locationt &loc,
922
+ code_blockt &init_code)
923
+ {
924
+ // Add the following code to init_code for each symbol that's been created:
925
+ // <type> <identifier>;
926
+ for (const symbolt * const symbol_ptr : symbols_created)
927
+ {
928
+ if (!symbol_ptr->is_static_lifetime )
929
+ {
930
+ code_declt decl (symbol_ptr->symbol_expr ());
931
+ decl.add_source_location ()=loc;
932
+ init_code.add (decl);
933
+ }
934
+ }
935
+ }
936
+
903
937
// / Similar to `gen_nondet_init`, but returns an object expression
904
938
// / rather than assigning to one.
905
939
// / \param type: type of new object to create
@@ -960,17 +994,7 @@ exprt object_factory(
960
994
typet (),
961
995
update_in_placet::NO_UPDATE_IN_PLACE);
962
996
963
- // Add the following code to init_code for each symbol that's been created:
964
- // <type> <identifier>;
965
- for (const symbolt * const symbol_ptr : symbols_created)
966
- {
967
- if (!symbol_ptr->is_static_lifetime )
968
- {
969
- code_declt decl (symbol_ptr->symbol_expr ());
970
- decl.add_source_location ()=loc;
971
- init_code.add (decl);
972
- }
973
- }
997
+ declare_created_symbols (symbols_created, loc, init_code);
974
998
975
999
init_code.append (assignments);
976
1000
return object;
@@ -1026,17 +1050,7 @@ void gen_nondet_init(
1026
1050
typet (),
1027
1051
update_in_place);
1028
1052
1029
- // Add the following code to init_code for each symbol that's been created:
1030
- // <type> <identifier>;
1031
- for (const symbolt * const symbol_ptr : symbols_created)
1032
- {
1033
- if (!symbol_ptr->is_static_lifetime )
1034
- {
1035
- code_declt decl (symbol_ptr->symbol_expr ());
1036
- decl.add_source_location ()=loc;
1037
- init_code.add (decl);
1038
- }
1039
- }
1053
+ declare_created_symbols (symbols_created, loc, init_code);
1040
1054
1041
1055
init_code.append (assignments);
1042
1056
}
0 commit comments