Skip to content

Commit 9f0626c

Browse files
Prefix temporary var names with function id
Temporary variable names must be globally unique and changing the number of temporaries in one function must not change a variable name in another function. Otherwise, this has adverse effects on goto-diff. This commit gets rid of various global temporary variables counters that do not meet above criteria. Instead, we now always use the function id to prefix temporaries to eliminate cross-function effects and increment the numeric suffix only when the entire variable name already exists, using the rename facility.
1 parent ca678aa commit 9f0626c

21 files changed

+312
-243
lines changed

src/ansi-c/c_nondet_symbol_factory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ static const symbolt &c_new_tmp_symbol(
4343
const bool static_lifetime,
4444
const std::string &prefix="tmp")
4545
{
46-
symbolt &tmp_symbol=
47-
get_fresh_aux_symbol(type, "", prefix, loc, ID_C, symbol_table);
46+
symbolt &tmp_symbol = get_fresh_aux_symbol(
47+
type, id2string(loc.get_function()), prefix, loc, ID_C, symbol_table);
4848
tmp_symbol.is_static_lifetime=static_lifetime;
4949

5050
return tmp_symbol;

src/goto-instrument/code_contracts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ const symbolt &code_contractst::new_tmp_symbol(
250250
{
251251
return get_fresh_aux_symbol(
252252
type,
253-
"",
253+
id2string(source_location.get_function()),
254254
"tmp_cc",
255255
source_location,
256256
irep_idt(),

src/goto-programs/convert_nondet.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Reuben Thomas, [email protected]
1717
#include <java_bytecode/java_object_factory.h> // gen_nondet_init
1818

1919
#include <util/irep_ids.h>
20+
#include <util/fresh_symbol.h>
2021

2122
#include <memory>
2223

@@ -135,11 +136,13 @@ void convert_nondet(
135136
message_handlert &message_handler,
136137
const object_factory_parameterst &object_factory_parameters)
137138
{
139+
object_factory_parameterst parameters = object_factory_parameters;
140+
parameters.function_id = function.get_function_id();
138141
convert_nondet(
139142
function.get_goto_function().body,
140143
function.get_symbol_table(),
141144
message_handler,
142-
object_factory_parameters);
145+
parameters);
143146

144147
function.compute_location_numbers();
145148
}
@@ -158,6 +161,8 @@ void convert_nondet(
158161

159162
if(symbol.mode==ID_java)
160163
{
164+
object_factory_parameterst parameters = object_factory_parameters;
165+
parameters.function_id = f_it.first;
161166
convert_nondet(
162167
f_it.second.body,
163168
symbol_table,

src/goto-programs/goto_convert_class.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class goto_convertt:public messaget
3434
messaget(_message_handler),
3535
symbol_table(_symbol_table),
3636
ns(_symbol_table),
37-
temporary_counter(0),
3837
tmp_symbol_prefix("goto_convertt")
3938
{
4039
}
@@ -46,7 +45,6 @@ class goto_convertt:public messaget
4645
protected:
4746
symbol_table_baset &symbol_table;
4847
namespacet ns;
49-
unsigned temporary_counter;
5048
std::string tmp_symbol_prefix;
5149

5250
void goto_convert_rec(const codet &code, goto_programt &dest);

src/goto-programs/goto_convert_functions.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ void goto_convert_functionst::convert_function(
147147

148148
// make tmp variables local to function
149149
tmp_symbol_prefix=id2string(symbol.name)+"::$tmp::";
150-
temporary_counter=0;
151-
reset_temporary_counter();
152150

153151
f.type=to_code_type(symbol.type);
154152

src/goto-programs/goto_convert_side_effect.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,15 @@ void goto_convertt::remove_function_call(
379379

380380
new_base_name+='_';
381381
new_base_name+=id2string(symbol.base_name);
382-
new_base_name+="$"+std::to_string(++temporary_counter);
382+
new_base_name += "$0";
383383

384384
new_symbol.base_name=new_base_name;
385385
new_symbol.mode=symbol.mode;
386386
}
387387

388388
new_symbol.name=tmp_symbol_prefix+id2string(new_symbol.base_name);
389389

390+
// ensure that the name is unique
390391
new_name(new_symbol);
391392

392393
{
@@ -429,10 +430,11 @@ void goto_convertt::remove_cpp_new(
429430

430431
auxiliary_symbolt new_symbol;
431432

432-
new_symbol.base_name="new_ptr$"+std::to_string(++temporary_counter);
433+
new_symbol.base_name = "new_ptr$0";
433434
new_symbol.type=expr.type();
434435
new_symbol.name=tmp_symbol_prefix+id2string(new_symbol.base_name);
435436

437+
// ensure that the name is unique
436438
new_name(new_symbol);
437439

438440
code_declt decl;
@@ -480,11 +482,12 @@ void goto_convertt::remove_malloc(
480482
{
481483
auxiliary_symbolt new_symbol;
482484

483-
new_symbol.base_name="malloc_value$"+std::to_string(++temporary_counter);
485+
new_symbol.base_name = "malloc_value$0";
484486
new_symbol.type=expr.type();
485487
new_symbol.name=tmp_symbol_prefix+id2string(new_symbol.base_name);
486488
new_symbol.location=expr.source_location();
487489

490+
// ensure that the name is unique
488491
new_name(new_symbol);
489492

490493
code_declt decl;

src/goto-programs/remove_function_pointers.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,13 @@ void remove_function_pointerst::fix_return_type(
233233
code_type.return_type(), ns))
234234
return;
235235

236-
symbolt &tmp_symbol=
237-
get_fresh_aux_symbol(
238-
code_type.return_type(),
239-
"remove_function_pointers",
240-
"tmp_return_val",
241-
function_call.source_location(),
242-
irep_idt(),
243-
symbol_table);
236+
symbolt &tmp_symbol = get_fresh_aux_symbol(
237+
code_type.return_type(),
238+
id2string(function_call.source_location().get_function()),
239+
"tmp_return_val",
240+
function_call.source_location(),
241+
irep_idt(),
242+
symbol_table);
244243

245244
symbol_exprt tmp_symbol_expr;
246245
tmp_symbol_expr.type()=tmp_symbol.type;

src/goto-programs/remove_instanceof.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,13 @@ std::size_t remove_instanceoft::lower_instanceof(
106106
symbol_typet jlo=to_symbol_type(java_lang_object_type().subtype());
107107
exprt object_clsid=get_class_identifier_field(check_ptr, jlo, ns);
108108

109-
symbolt &newsym=
110-
get_fresh_aux_symbol(
111-
object_clsid.type(),
112-
"instanceof_tmp",
113-
"instanceof_tmp",
114-
source_locationt(),
115-
ID_java,
116-
symbol_table);
109+
symbolt &newsym = get_fresh_aux_symbol(
110+
object_clsid.type(),
111+
id2string(this_inst->function),
112+
"instanceof_tmp",
113+
source_locationt(),
114+
ID_java,
115+
symbol_table);
117116

118117
auto newinst=goto_program.insert_after(this_inst);
119118
newinst->make_assignment();

src/java_bytecode/java_entry_point.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,21 @@ exprt::operandst java_build_arguments(
203203
bool allow_null=
204204
!assume_init_pointers_not_null && !is_main && !is_this;
205205

206+
object_factory_parameterst parameters = object_factory_parameters;
207+
parameters.function_id = function.name;
208+
206209
// generate code to allocate and non-deterministicaly initialize the
207210
// argument
208-
main_arguments[param_number]=
209-
object_factory(
210-
p.type(),
211-
base_name,
212-
init_code,
213-
allow_null,
214-
symbol_table,
215-
object_factory_parameters,
216-
allocation_typet::LOCAL,
217-
function.location,
218-
pointer_type_selector);
211+
main_arguments[param_number] = object_factory(
212+
p.type(),
213+
base_name,
214+
init_code,
215+
allow_null,
216+
symbol_table,
217+
parameters,
218+
allocation_typet::LOCAL,
219+
function.location,
220+
pointer_type_selector);
219221

220222
// record as an input
221223
codet input(ID_input);

0 commit comments

Comments
 (0)