Skip to content

Commit

Permalink
Prefix temporary var names with function id
Browse files Browse the repository at this point in the history
 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.
  • Loading branch information
peterschrammel committed Apr 17, 2018
1 parent ca678aa commit 9f0626c
Show file tree
Hide file tree
Showing 21 changed files with 312 additions and 243 deletions.
4 changes: 2 additions & 2 deletions src/ansi-c/c_nondet_symbol_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ static const symbolt &c_new_tmp_symbol(
const bool static_lifetime,
const std::string &prefix="tmp")
{
symbolt &tmp_symbol=
get_fresh_aux_symbol(type, "", prefix, loc, ID_C, symbol_table);
symbolt &tmp_symbol = get_fresh_aux_symbol(
type, id2string(loc.get_function()), prefix, loc, ID_C, symbol_table);
tmp_symbol.is_static_lifetime=static_lifetime;

return tmp_symbol;
Expand Down
2 changes: 1 addition & 1 deletion src/goto-instrument/code_contracts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ const symbolt &code_contractst::new_tmp_symbol(
{
return get_fresh_aux_symbol(
type,
"",
id2string(source_location.get_function()),
"tmp_cc",
source_location,
irep_idt(),
Expand Down
7 changes: 6 additions & 1 deletion src/goto-programs/convert_nondet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Author: Reuben Thomas, [email protected]
#include <java_bytecode/java_object_factory.h> // gen_nondet_init

#include <util/irep_ids.h>
#include <util/fresh_symbol.h>

#include <memory>

Expand Down Expand Up @@ -135,11 +136,13 @@ void convert_nondet(
message_handlert &message_handler,
const object_factory_parameterst &object_factory_parameters)
{
object_factory_parameterst parameters = object_factory_parameters;
parameters.function_id = function.get_function_id();
convert_nondet(
function.get_goto_function().body,
function.get_symbol_table(),
message_handler,
object_factory_parameters);
parameters);

function.compute_location_numbers();
}
Expand All @@ -158,6 +161,8 @@ void convert_nondet(

if(symbol.mode==ID_java)
{
object_factory_parameterst parameters = object_factory_parameters;
parameters.function_id = f_it.first;
convert_nondet(
f_it.second.body,
symbol_table,
Expand Down
2 changes: 0 additions & 2 deletions src/goto-programs/goto_convert_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class goto_convertt:public messaget
messaget(_message_handler),
symbol_table(_symbol_table),
ns(_symbol_table),
temporary_counter(0),
tmp_symbol_prefix("goto_convertt")
{
}
Expand All @@ -46,7 +45,6 @@ class goto_convertt:public messaget
protected:
symbol_table_baset &symbol_table;
namespacet ns;
unsigned temporary_counter;
std::string tmp_symbol_prefix;

void goto_convert_rec(const codet &code, goto_programt &dest);
Expand Down
2 changes: 0 additions & 2 deletions src/goto-programs/goto_convert_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ void goto_convert_functionst::convert_function(

// make tmp variables local to function
tmp_symbol_prefix=id2string(symbol.name)+"::$tmp::";
temporary_counter=0;
reset_temporary_counter();

f.type=to_code_type(symbol.type);

Expand Down
9 changes: 6 additions & 3 deletions src/goto-programs/goto_convert_side_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,15 @@ void goto_convertt::remove_function_call(

new_base_name+='_';
new_base_name+=id2string(symbol.base_name);
new_base_name+="$"+std::to_string(++temporary_counter);
new_base_name += "$0";

new_symbol.base_name=new_base_name;
new_symbol.mode=symbol.mode;
}

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

// ensure that the name is unique
new_name(new_symbol);

{
Expand Down Expand Up @@ -429,10 +430,11 @@ void goto_convertt::remove_cpp_new(

auxiliary_symbolt new_symbol;

new_symbol.base_name="new_ptr$"+std::to_string(++temporary_counter);
new_symbol.base_name = "new_ptr$0";
new_symbol.type=expr.type();
new_symbol.name=tmp_symbol_prefix+id2string(new_symbol.base_name);

// ensure that the name is unique
new_name(new_symbol);

code_declt decl;
Expand Down Expand Up @@ -480,11 +482,12 @@ void goto_convertt::remove_malloc(
{
auxiliary_symbolt new_symbol;

new_symbol.base_name="malloc_value$"+std::to_string(++temporary_counter);
new_symbol.base_name = "malloc_value$0";
new_symbol.type=expr.type();
new_symbol.name=tmp_symbol_prefix+id2string(new_symbol.base_name);
new_symbol.location=expr.source_location();

// ensure that the name is unique
new_name(new_symbol);

code_declt decl;
Expand Down
15 changes: 7 additions & 8 deletions src/goto-programs/remove_function_pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,13 @@ void remove_function_pointerst::fix_return_type(
code_type.return_type(), ns))
return;

symbolt &tmp_symbol=
get_fresh_aux_symbol(
code_type.return_type(),
"remove_function_pointers",
"tmp_return_val",
function_call.source_location(),
irep_idt(),
symbol_table);
symbolt &tmp_symbol = get_fresh_aux_symbol(
code_type.return_type(),
id2string(function_call.source_location().get_function()),
"tmp_return_val",
function_call.source_location(),
irep_idt(),
symbol_table);

symbol_exprt tmp_symbol_expr;
tmp_symbol_expr.type()=tmp_symbol.type;
Expand Down
15 changes: 7 additions & 8 deletions src/goto-programs/remove_instanceof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,13 @@ std::size_t remove_instanceoft::lower_instanceof(
symbol_typet jlo=to_symbol_type(java_lang_object_type().subtype());
exprt object_clsid=get_class_identifier_field(check_ptr, jlo, ns);

symbolt &newsym=
get_fresh_aux_symbol(
object_clsid.type(),
"instanceof_tmp",
"instanceof_tmp",
source_locationt(),
ID_java,
symbol_table);
symbolt &newsym = get_fresh_aux_symbol(
object_clsid.type(),
id2string(this_inst->function),
"instanceof_tmp",
source_locationt(),
ID_java,
symbol_table);

auto newinst=goto_program.insert_after(this_inst);
newinst->make_assignment();
Expand Down
24 changes: 13 additions & 11 deletions src/java_bytecode/java_entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,21 @@ exprt::operandst java_build_arguments(
bool allow_null=
!assume_init_pointers_not_null && !is_main && !is_this;

object_factory_parameterst parameters = object_factory_parameters;
parameters.function_id = function.name;

// generate code to allocate and non-deterministicaly initialize the
// argument
main_arguments[param_number]=
object_factory(
p.type(),
base_name,
init_code,
allow_null,
symbol_table,
object_factory_parameters,
allocation_typet::LOCAL,
function.location,
pointer_type_selector);
main_arguments[param_number] = object_factory(
p.type(),
base_name,
init_code,
allow_null,
symbol_table,
parameters,
allocation_typet::LOCAL,
function.location,
pointer_type_selector);

// record as an input
codet input(ID_input);
Expand Down
Loading

0 comments on commit 9f0626c

Please sign in to comment.