Skip to content

Commit b3d7d82

Browse files
Prefix identifiers in stubs with function name
The name of an auxiliary variable must not depend on other functions in the symbol table.
1 parent 0f2cc3a commit b3d7d82

File tree

8 files changed

+80
-7
lines changed

8 files changed

+80
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Opaque extends Exception
2+
{
3+
public static Opaque static_field;
4+
public Opaque field;
5+
6+
public Opaque(Opaque o) {
7+
}
8+
9+
public static Opaque static_method(Opaque o) {
10+
return o;
11+
}
12+
13+
public Opaque[] method(Opaque[] o) {
14+
return o;
15+
}
16+
}
635 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
public class Test
2+
{
3+
public static void f00(Opaque z)
4+
{
5+
try {
6+
Opaque x = new Opaque(Opaque.static_field);
7+
Opaque[] a = {Opaque.static_method(x.field), z};
8+
Opaque[] y = x.method(a);
9+
throw y[0];
10+
} catch(Opaque o) {
11+
}
12+
}
13+
public Opaque f01(Opaque z)
14+
{
15+
try {
16+
Opaque x = new Opaque(Opaque.static_field);
17+
Opaque[] a = {Opaque.static_method(x.field), z};
18+
Opaque[] y = x.method(a);
19+
throw y[0];
20+
} catch(Opaque o) {
21+
return o;
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Test.class
3+
--show-symbol-table
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^Symbol\.*: java::Opaque\.static_method:\(LOpaque;\)LOpaque;::malloc_site\$[0-3]?$
7+
^Symbol\.*: java::Opaque\.method:\(\[LOpaque;\)\[LOpaque;::malloc_site\$[0-3]?$
8+
--
9+
^Symbol\.*: malloc_site
10+
^Symbol\.*: to_construct
11+
^Symbol\.*: to_return
12+
^Symbol\.*: this
13+
^Symbol\.*: caught_exception
14+
^Symbol\.*: anonlocal
15+
^Symbol\.*: stub_ignored_arg
16+
^Symbol\.*: #return_value
17+
^Symbol\.*: return_tmp
18+
^Symbol\.*: new_tmp
19+
^Symbol\.*: tmp_new_data_array
20+
^Symbol\.*: newarray_tmp
21+
--
22+
Does not work with symex-driven lazy loading because we want to check the
23+
symbol table for the entire program.

jbmc/src/java_bytecode/java_entry_point.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,14 @@ static void java_static_lifetime_init(
117117
symbol_table_baset &symbol_table,
118118
const source_locationt &source_location,
119119
bool assume_init_pointers_not_null,
120-
const object_factory_parameterst &object_factory_parameters,
120+
object_factory_parameterst object_factory_parameters,
121121
const select_pointer_typet &pointer_type_selector,
122122
bool string_refinement_enabled,
123123
message_handlert &message_handler)
124124
{
125125
symbolt &initialize_symbol=*symbol_table.get_writeable(INITIALIZE_FUNCTION);
126126
code_blockt &code_block=to_code_block(to_code(initialize_symbol.value));
127+
object_factory_parameters.function_id = initialize_symbol.name;
127128

128129
// We need to zero out all static variables, or nondet-initialize if they're
129130
// external. Iterate over a copy of the symtab, as its iterators are

jbmc/src/java_bytecode/java_object_factory.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ exprt object_factory(
14881488
code_blockt &init_code,
14891489
bool allow_null,
14901490
symbol_table_baset &symbol_table,
1491-
const object_factory_parameterst &parameters,
1491+
object_factory_parameterst parameters,
14921492
allocation_typet alloc_type,
14931493
const source_locationt &loc,
14941494
const select_pointer_typet &pointer_type_selector)
@@ -1503,6 +1503,7 @@ exprt object_factory(
15031503
main_symbol.base_name=base_name;
15041504
main_symbol.type=type;
15051505
main_symbol.location=loc;
1506+
parameters.function_id = goto_functionst::entry_point();
15061507

15071508
exprt object=main_symbol.symbol_expr();
15081509

jbmc/src/java_bytecode/java_object_factory.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ exprt object_factory(
9292
code_blockt &init_code,
9393
bool allow_null,
9494
symbol_table_baset &symbol_table,
95-
const object_factory_parameterst &parameters,
95+
object_factory_parameterst parameters,
9696
allocation_typet alloc_type,
9797
const source_locationt &location,
9898
const select_pointer_typet &pointer_type_selector);

jbmc/src/java_bytecode/simple_method_stubbing.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class java_simple_method_stubst
3939
const typet &expected_type,
4040
const exprt &ptr,
4141
const source_locationt &loc,
42+
const irep_idt &function_id,
4243
code_blockt &parent_block,
4344
unsigned insert_before_index,
4445
bool is_constructor,
@@ -77,6 +78,7 @@ void java_simple_method_stubst::create_method_stub_at(
7778
const typet &expected_type,
7879
const exprt &ptr,
7980
const source_locationt &loc,
81+
const irep_idt &function_id,
8082
code_blockt &parent_block,
8183
const unsigned insert_before_index,
8284
const bool is_constructor,
@@ -108,6 +110,8 @@ void java_simple_method_stubst::create_method_stub_at(
108110

109111
// Generate new instructions.
110112
code_blockt new_instructions;
113+
object_factory_parameterst parameters = object_factory_parameters;
114+
parameters.function_id = function_id;
111115
gen_nondet_init(
112116
to_init,
113117
new_instructions,
@@ -116,7 +120,7 @@ void java_simple_method_stubst::create_method_stub_at(
116120
is_constructor,
117121
allocation_typet::DYNAMIC,
118122
!assume_non_null,
119-
object_factory_parameters,
123+
parameters,
120124
update_in_place ? update_in_placet::MUST_UPDATE_IN_PLACE
121125
: update_in_placet::NO_UPDATE_IN_PLACE);
122126

@@ -155,7 +159,7 @@ void java_simple_method_stubst::create_method_stub(symbolt &symbol)
155159
const typet &this_type = this_argument.type();
156160
symbolt &init_symbol = get_fresh_aux_symbol(
157161
this_type,
158-
"to_construct",
162+
id2string(symbol.name),
159163
"to_construct",
160164
synthesized_source_location,
161165
ID_java,
@@ -169,6 +173,7 @@ void java_simple_method_stubst::create_method_stub(symbolt &symbol)
169173
this_type,
170174
init_symbol_expression,
171175
synthesized_source_location,
176+
symbol.name,
172177
new_instructions,
173178
1,
174179
true,
@@ -181,14 +186,16 @@ void java_simple_method_stubst::create_method_stub(symbolt &symbol)
181186
{
182187
symbolt &to_return_symbol = get_fresh_aux_symbol(
183188
required_return_type,
184-
"to_return",
189+
id2string(symbol.name),
185190
"to_return",
186191
synthesized_source_location,
187192
ID_java,
188193
symbol_table);
189194
const exprt &to_return = to_return_symbol.symbol_expr();
190195
if(to_return_symbol.type.id() != ID_pointer)
191196
{
197+
object_factory_parameterst parameters = object_factory_parameters;
198+
parameters.function_id = symbol.name;
192199
gen_nondet_init(
193200
to_return,
194201
new_instructions,
@@ -197,14 +204,15 @@ void java_simple_method_stubst::create_method_stub(symbolt &symbol)
197204
false,
198205
allocation_typet::LOCAL, // Irrelevant as type is primitive
199206
!assume_non_null,
200-
object_factory_parameters,
207+
parameters,
201208
update_in_placet::NO_UPDATE_IN_PLACE);
202209
}
203210
else
204211
create_method_stub_at(
205212
required_return_type,
206213
to_return,
207214
synthesized_source_location,
215+
symbol.name,
208216
new_instructions,
209217
0,
210218
false,

0 commit comments

Comments
 (0)