Skip to content

Commit 9f9ee07

Browse files
authored
Merge pull request #6569 from tautschnig/bugfixes/6566
C nondet factory: Ensure parameter initialisers use unique symbol names
2 parents fe33713 + de5bbd1 commit 9f9ee07

File tree

7 files changed

+51
-50
lines changed

7 files changed

+51
-50
lines changed

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 13 additions & 18 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>
@@ -103,7 +104,7 @@ class java_object_factoryt
103104
update_in_placet,
104105
const source_locationt &location);
105106

106-
void add_created_symbol(const symbolt *symbol);
107+
void add_created_symbol(const symbolt &symbol);
107108

108109
void declare_created_symbols(code_blockt &init_code);
109110

@@ -1110,9 +1111,9 @@ void java_object_factoryt::gen_nondet_init(
11101111
}
11111112
}
11121113

1113-
void java_object_factoryt::add_created_symbol(const symbolt *symbol_ptr)
1114+
void java_object_factoryt::add_created_symbol(const symbolt &symbol)
11141115
{
1115-
allocate_objects.add_created_symbol(symbol_ptr);
1116+
allocate_objects.add_created_symbol(symbol);
11161117
}
11171118

11181119
void java_object_factoryt::declare_created_symbols(code_blockt &init_code)
@@ -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);

src/ansi-c/c_nondet_symbol_factory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class symbol_factoryt
5656
recursion_sett recursion_set = recursion_sett(),
5757
const bool assign_const = true);
5858

59-
void add_created_symbol(const symbolt *symbol_ptr)
59+
void add_created_symbol(const symbolt &symbol)
6060
{
61-
allocate_objects.add_created_symbol(symbol_ptr);
61+
allocate_objects.add_created_symbol(symbol);
6262
}
6363

6464
void declare_created_symbols(code_blockt &init_code)

src/goto-programs/allocate_objects.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ symbol_exprt allocate_objectst::allocate_automatic_local_object(
116116
symbol_mode,
117117
symbol_table);
118118

119-
symbols_created.push_back(&aux_symbol);
119+
add_created_symbol(aux_symbol);
120120

121121
return aux_symbol.symbol_expr();
122122
}
@@ -153,7 +153,7 @@ exprt allocate_objectst::allocate_dynamic_object_symbol(
153153
symbol_mode,
154154
symbol_table);
155155

156-
symbols_created.push_back(&malloc_sym);
156+
add_created_symbol(malloc_sym);
157157

158158
code_frontend_assignt assign =
159159
make_allocate_code(malloc_sym.symbol_expr(), object_size.value());
@@ -194,7 +194,7 @@ exprt allocate_objectst::allocate_non_dynamic_object(
194194
symbol_table);
195195

196196
aux_symbol.is_static_lifetime = static_lifetime;
197-
symbols_created.push_back(&aux_symbol);
197+
add_created_symbol(aux_symbol);
198198

199199
exprt aoe = typecast_exprt::conditional_cast(
200200
address_of_exprt(aux_symbol.symbol_expr()), target_expr.type());
@@ -215,10 +215,10 @@ exprt allocate_objectst::allocate_non_dynamic_object(
215215

216216
/// Add a pointer to a symbol to the list of pointers to symbols created so far
217217
///
218-
/// \param symbol_ptr: pointer to a symbol in the symbol table
219-
void allocate_objectst::add_created_symbol(const symbolt *symbol_ptr)
218+
/// \param symbol: symbol in the symbol table
219+
void allocate_objectst::add_created_symbol(const symbolt &symbol)
220220
{
221-
symbols_created.push_back(symbol_ptr);
221+
symbols_created.push_back(symbol.name);
222222
}
223223

224224
/// Adds declarations for all non-static symbols created
@@ -228,11 +228,12 @@ void allocate_objectst::declare_created_symbols(code_blockt &init_code)
228228
{
229229
// Add the following code to init_code for each symbol that's been created:
230230
// <type> <identifier>;
231-
for(const symbolt *const symbol_ptr : symbols_created)
231+
for(const auto &symbol_id : symbols_created)
232232
{
233-
if(!symbol_ptr->is_static_lifetime)
233+
const symbolt &symbol = ns.lookup(symbol_id);
234+
if(!symbol.is_static_lifetime)
234235
{
235-
code_declt decl(symbol_ptr->symbol_expr());
236+
code_declt decl{symbol.symbol_expr()};
236237
decl.add_source_location() = source_location;
237238
init_code.add(decl);
238239
}
@@ -246,10 +247,11 @@ void allocate_objectst::mark_created_symbols_as_input(code_blockt &init_code)
246247
{
247248
// Add the following code to init_code for each symbol that's been created:
248249
// INPUT("<identifier>", <identifier>);
249-
for(symbolt const *symbol_ptr : symbols_created)
250+
for(const auto &symbol_id : symbols_created)
250251
{
251-
init_code.add(code_inputt{
252-
symbol_ptr->base_name, symbol_ptr->symbol_expr(), source_location});
252+
const symbolt &symbol = ns.lookup(symbol_id);
253+
init_code.add(
254+
code_inputt{symbol.base_name, symbol.symbol_expr(), source_location});
253255
}
254256
}
255257

src/goto-programs/allocate_objects.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class allocate_objectst
9393
const typet &allocate_type,
9494
const irep_idt &basename_prefix = "tmp");
9595

96-
void add_created_symbol(const symbolt *symbol_ptr);
96+
void add_created_symbol(const symbolt &symbol);
9797

9898
void declare_created_symbols(code_blockt &init_code);
9999

@@ -107,7 +107,7 @@ class allocate_objectst
107107
symbol_table_baset &symbol_table;
108108
const namespacet ns;
109109

110-
std::vector<const symbolt *> symbols_created;
110+
std::vector<irep_idt> symbols_created;
111111

112112
exprt allocate_non_dynamic_object(
113113
code_blockt &assignments,

0 commit comments

Comments
 (0)