Skip to content

Commit e87293a

Browse files
author
Daniel Kroening
committed
change return_value_identifier() to return_value_symbol
All users of this function either compare the result with a symbol_exprt or build a symbol_exprt. This change makes the function return a symbol_exprt instead of the identifier, which reduces effort at the call site.
1 parent 5a2a09e commit e87293a

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

src/goto-programs/mm_io.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ void mm_io(
5656
const code_typet &ct=to_code_type(mm_io_r.type());
5757

5858
irep_idt identifier=to_symbol_expr(mm_io_r).get_identifier();
59-
irep_idt r_identifier = return_value_identifier(identifier, ns);
60-
symbol_exprt return_value(r_identifier, ct.return_type());
59+
auto return_value = return_value_symbol(identifier, ns);
6160
if_exprt if_expr(integer_address(d.pointer()), return_value, d);
6261
if(!replace_expr(d, if_expr, a.rhs()))
6362
it->set_assign(a);

src/goto-programs/remove_returns.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ optionalt<symbol_exprt>
6464
remove_returnst::get_or_create_return_value_symbol(const irep_idt &function_id)
6565
{
6666
const namespacet ns(symbol_table);
67-
const irep_idt symbol_name = return_value_identifier(function_id, ns);
68-
const symbolt *existing_symbol = symbol_table.lookup(symbol_name);
69-
if(existing_symbol != nullptr)
70-
return existing_symbol->symbol_expr();
67+
const auto symbol_expr = return_value_symbol(function_id, ns);
68+
const auto symbol_name = symbol_expr.get_identifier();
69+
if(symbol_table.has_symbol(symbol_name))
70+
return symbol_expr;
7171

7272
const symbolt &function_symbol = symbol_table.lookup_ref(function_id);
7373
const typet &return_type = to_code_type(function_symbol.type).return_type();
@@ -296,7 +296,8 @@ bool remove_returnst::restore_returns(
296296

297297
// do we have X#return_value?
298298
const namespacet ns(symbol_table);
299-
auto rv_name = return_value_identifier(function_id, ns);
299+
auto rv_symbol = return_value_symbol(function_id, ns);
300+
auto rv_name = rv_symbol.get_identifier();
300301

301302
symbol_tablet::symbolst::const_iterator rv_it=
302303
symbol_table.symbols.find(rv_name);
@@ -368,12 +369,8 @@ void remove_returnst::undo_function_calls(
368369

369370
const code_assignt &assign = next->get_assign();
370371

371-
if(assign.rhs().id()!=ID_symbol)
372-
continue;
373-
374-
irep_idt rv_name = return_value_identifier(function_id, ns);
375-
const symbol_exprt &rhs=to_symbol_expr(assign.rhs());
376-
if(rhs.get_identifier()!=rv_name)
372+
const auto rv_symbol = return_value_symbol(function_id, ns);
373+
if(assign.rhs() != rv_symbol)
377374
continue;
378375

379376
// restore the previous assignment
@@ -414,7 +411,10 @@ void restore_returns(goto_modelt &goto_model)
414411
rr.restore(goto_model.goto_functions);
415412
}
416413

417-
irep_idt return_value_identifier(const irep_idt &identifier, const namespacet &)
414+
symbol_exprt
415+
return_value_symbol(const irep_idt &identifier, const namespacet &ns)
418416
{
419-
return id2string(identifier) + RETURN_VALUE_SUFFIX;
417+
const symbolt &function_symbol = ns.lookup(identifier);
418+
const typet &return_type = to_code_type(function_symbol.type).return_type();
419+
return symbol_exprt(id2string(identifier) + RETURN_VALUE_SUFFIX, return_type);
420420
}

src/goto-programs/remove_returns.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ Date: September 2009
7878
class goto_functionst;
7979
class goto_model_functiont;
8080
class goto_modelt;
81-
class symbol_table_baset;
8281
class namespacet;
82+
class symbol_table_baset;
83+
class symbol_exprt;
8384

8485
void remove_returns(symbol_table_baset &, goto_functionst &);
8586

@@ -94,8 +95,8 @@ void restore_returns(symbol_table_baset &, goto_functionst &);
9495

9596
void restore_returns(goto_modelt &);
9697

97-
/// produces the identifier that is used to store the return
98+
/// produces the symbol that is used to store the return
9899
/// value of the function with the given identifier
99-
irep_idt return_value_identifier(const irep_idt &, const namespacet &);
100+
symbol_exprt return_value_symbol(const irep_idt &, const namespacet &);
100101

101102
#endif // CPROVER_GOTO_PROGRAMS_REMOVE_RETURNS_H

src/goto-programs/replace_calls.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,18 @@ void replace_callst::operator()(
9797
PRECONDITION(base_type_eq(f_it1->second.type, f_it2->second.type, ns));
9898

9999
// check that returns have not been removed
100-
goto_programt::const_targett next_it = std::next(it);
101-
if(next_it != goto_program.instructions.end() && next_it->is_assign())
100+
if(to_code_type(f_it1->second.type).return_type().id() != ID_empty)
102101
{
103-
const code_assignt &ca = next_it->get_assign();
104-
const exprt &rhs = ca.rhs();
105-
106-
INVARIANT(
107-
rhs.id() != ID_symbol || to_symbol_expr(rhs).get_identifier() !=
108-
return_value_identifier(id, ns),
109-
"returns must not be removed before replacing calls");
102+
goto_programt::const_targett next_it = std::next(it);
103+
if(next_it != goto_program.instructions.end() && next_it->is_assign())
104+
{
105+
const code_assignt &ca = next_it->get_assign();
106+
const exprt &rhs = ca.rhs();
107+
108+
INVARIANT(
109+
rhs != return_value_symbol(id, ns),
110+
"returns must not be removed before replacing calls");
111+
}
110112
}
111113

112114
// Finally modify the call

0 commit comments

Comments
 (0)