Skip to content

Commit 5bc1d55

Browse files
committed
C and Java nondet factories: use unique symbol names
The nondet symbol factory uses "tmp" as a default basename prefix, and in all other places already generated unique names using `get_fresh_aux_symbol`. This function, however, will happily use exactly that basename when there wouldn't be a conflict. The code fixed in this commit, however, did not yet use this facility, and just assumed that each parameter of the target function would result in a unique local name. A parameter named "tmp," then, resulted in a conflict. Consistently using `get_fresh_aux_symbol` addresses this problem. Fixes: #6566 Co-authored-by: Matthias Güdemann <[email protected]> fixup! C nondet factory: Ensure parameter initialisers use unique symbol names
1 parent 08d5056 commit 5bc1d55

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected]
1111
#include <util/arith_tools.h>
1212
#include <util/array_element_from_pointer.h>
1313
#include <util/expr_initializer.h>
14+
#include <util/fresh_symbol.h>
1415
#include <util/message.h>
1516
#include <util/nondet_bool.h>
1617
#include <util/prefix.h>
@@ -1551,24 +1552,18 @@ exprt object_factory(
15511552
const select_pointer_typet &pointer_type_selector,
15521553
message_handlert &log)
15531554
{
1554-
irep_idt identifier=id2string(goto_functionst::entry_point())+
1555-
"::"+id2string(base_name);
1556-
1557-
auxiliary_symbolt main_symbol;
1558-
main_symbol.mode=ID_java;
1559-
main_symbol.is_static_lifetime=false;
1560-
main_symbol.name=identifier;
1561-
main_symbol.base_name=base_name;
1562-
main_symbol.type=type;
1563-
main_symbol.location=loc;
1555+
const symbolt &main_symbol = get_fresh_aux_symbol(
1556+
type,
1557+
id2string(goto_functionst::entry_point()),
1558+
id2string(base_name),
1559+
loc,
1560+
ID_java,
1561+
symbol_table);
1562+
15641563
parameters.function_id = goto_functionst::entry_point();
15651564

15661565
exprt object=main_symbol.symbol_expr();
15671566

1568-
symbolt *main_symbol_ptr;
1569-
bool moving_symbol_failed=symbol_table.move(main_symbol, main_symbol_ptr);
1570-
CHECK_RETURN(!moving_symbol_failed);
1571-
15721567
java_object_factoryt state(
15731568
loc, parameters, symbol_table, pointer_type_selector, log);
15741569
code_blockt assignments;
@@ -1583,7 +1578,7 @@ exprt object_factory(
15831578
update_in_placet::NO_UPDATE_IN_PLACE,
15841579
loc);
15851580

1586-
state.add_created_symbol(main_symbol_ptr);
1581+
state.add_created_symbol(&main_symbol);
15871582
state.declare_created_symbols(init_code);
15881583

15891584
assert_type_consistency(assignments);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
void f(int *b, int tmp)
2+
{
3+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--function f
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
VERIFICATION SUCCESSFUL
7+
--
8+
^warning: ignoring

src/ansi-c/c_nondet_symbol_factory.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Diffblue Ltd.
1515

1616
#include <util/arith_tools.h>
1717
#include <util/c_types.h>
18+
#include <util/fresh_symbol.h>
1819
#include <util/namespace.h>
1920
#include <util/nondet_bool.h>
2021
#include <util/pointer_expr.h>
@@ -204,23 +205,15 @@ symbol_exprt c_nondet_symbol_factory(
204205
const c_object_factory_parameterst &object_factory_parameters,
205206
const lifetimet lifetime)
206207
{
207-
irep_idt identifier=id2string(goto_functionst::entry_point())+
208-
"::"+id2string(base_name);
209-
210-
auxiliary_symbolt main_symbol;
211-
main_symbol.mode=ID_C;
212-
main_symbol.is_static_lifetime=false;
213-
main_symbol.name=identifier;
214-
main_symbol.base_name=base_name;
215-
main_symbol.type=type;
216-
main_symbol.location=loc;
217-
208+
const symbolt &main_symbol = get_fresh_aux_symbol(
209+
type,
210+
id2string(goto_functionst::entry_point()),
211+
id2string(base_name),
212+
loc,
213+
ID_C,
214+
symbol_table);
218215
symbol_exprt main_symbol_expr=main_symbol.symbol_expr();
219216

220-
symbolt *main_symbol_ptr;
221-
bool moving_symbol_failed=symbol_table.move(main_symbol, main_symbol_ptr);
222-
CHECK_RETURN(!moving_symbol_failed);
223-
224217
symbol_factoryt state(
225218
symbol_table,
226219
loc,
@@ -231,7 +224,7 @@ symbol_exprt c_nondet_symbol_factory(
231224
code_blockt assignments;
232225
state.gen_nondet_init(assignments, main_symbol_expr);
233226

234-
state.add_created_symbol(main_symbol_ptr);
227+
state.add_created_symbol(&main_symbol);
235228
state.declare_created_symbols(init_code);
236229

237230
init_code.append(assignments);

0 commit comments

Comments
 (0)