Skip to content

Commit 39743ab

Browse files
authored
Merge pull request #1156 from smowton/smowton/fix/global_variable_nondet_init
Fix nondet static field initialisation
2 parents 8738274 + f005427 commit 39743ab

File tree

9 files changed

+166
-92
lines changed

9 files changed

+166
-92
lines changed
569 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
test.class
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class A
2+
{
3+
public static A external_global;
4+
public int i;
5+
};
6+
7+
public class test
8+
{
9+
public static void main()
10+
{
11+
if(A.external_global == null)
12+
return;
13+
A local = A.external_global;
14+
assert(local instanceof A);
15+
}
16+
}

src/goto-programs/convert_nondet.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static goto_programt::targett insert_nondet_init_code(
8585
symbol_table,
8686
source_loc,
8787
true,
88-
true,
88+
allocation_typet::DYNAMIC,
8989
!nullable,
9090
max_nondet_array_length,
9191
update_in_placet::NO_UPDATE_IN_PLACE);

src/java_bytecode/java_bytecode_convert_method.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,10 @@ codet java_bytecode_convert_methodt::convert_instructions(
20142014
const bool is_assertions_disabled_field=
20152015
field_name.find("$assertionsDisabled")!=std::string::npos;
20162016
symbol_expr.set_identifier(arg0.get_string(ID_class)+"."+field_name);
2017+
2018+
// If external, create a symbol table entry for this static field:
2019+
check_static_field_stub(symbol_expr, field_name);
2020+
20172021
if(lazy_methods)
20182022
{
20192023
if(arg0.type().id()==ID_symbol)
@@ -2056,6 +2060,10 @@ codet java_bytecode_convert_methodt::convert_instructions(
20562060
symbol_exprt symbol_expr(arg0.type());
20572061
const auto &field_name=arg0.get_string(ID_component_name);
20582062
symbol_expr.set_identifier(arg0.get_string(ID_class)+"."+field_name);
2063+
2064+
// If external, create a symbol table entry for this static field:
2065+
check_static_field_stub(symbol_expr, field_name);
2066+
20592067
if(lazy_methods && arg0.type().id()==ID_symbol)
20602068
{
20612069
lazy_methods->add_needed_class(

src/java_bytecode/java_bytecode_instrument.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ codet java_bytecode_instrumentt::throw_exception(
113113
false,
114114
symbol_table,
115115
max_array_length,
116+
allocation_typet::LOCAL,
116117
original_loc);
117118
}
118119
else

src/java_bytecode/java_entry_point.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ void java_static_lifetime_init(
118118
allow_null,
119119
symbol_table,
120120
max_nondet_array_length,
121+
allocation_typet::GLOBAL,
121122
source_location);
122123
code_assignt assignment(sym.symbol_expr(), newsym);
123124
code_block.add(assignment);
@@ -180,6 +181,7 @@ exprt::operandst java_build_arguments(
180181
allow_null,
181182
symbol_table,
182183
max_nondet_array_length,
184+
allocation_typet::LOCAL,
183185
function.location);
184186

185187
// record as an input

0 commit comments

Comments
 (0)