Skip to content

Commit 0475c87

Browse files
author
Daniel Kroening
committed
introduce return_value_identifier(...)
This encapsulates the scheme that is used to construct the identifier for the symbol that holds the return value of a given function.
1 parent a847d8c commit 0475c87

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

src/goto-programs/mm_io.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +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=id2string(identifier)+RETURN_VALUE_SUFFIX;
59+
irep_idt r_identifier = return_value_identifier(identifier, ns);
6060
symbol_exprt return_value(r_identifier, ct.return_type());
6161
if_exprt if_expr(integer_address(d.pointer()), return_value, d);
6262
if(!replace_expr(d, if_expr, a.rhs()))

src/goto-programs/remove_returns.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Date: September 2009
1919

2020
#include "remove_skip.h"
2121

22+
#define RETURN_VALUE_SUFFIX "#return_value"
23+
2224
class remove_returnst
2325
{
2426
public:
@@ -61,7 +63,8 @@ class remove_returnst
6163
optionalt<symbol_exprt>
6264
remove_returnst::get_or_create_return_value_symbol(const irep_idt &function_id)
6365
{
64-
const irep_idt symbol_name = id2string(function_id) + RETURN_VALUE_SUFFIX;
66+
const namespacet ns(symbol_table);
67+
const irep_idt symbol_name = return_value_identifier(function_id, ns);
6568
const symbolt *existing_symbol = symbol_table.lookup(symbol_name);
6669
if(existing_symbol != nullptr)
6770
return existing_symbol->symbol_expr();
@@ -292,7 +295,8 @@ bool remove_returnst::restore_returns(
292295
const irep_idt function_id=f_it->first;
293296

294297
// do we have X#return_value?
295-
std::string rv_name=id2string(function_id)+RETURN_VALUE_SUFFIX;
298+
const namespacet ns(symbol_table);
299+
auto rv_name = return_value_identifier(function_id, ns);
296300

297301
symbol_tablet::symbolst::const_iterator rv_it=
298302
symbol_table.symbols.find(rv_name);
@@ -367,7 +371,7 @@ void remove_returnst::undo_function_calls(
367371
if(assign.rhs().id()!=ID_symbol)
368372
continue;
369373

370-
irep_idt rv_name=id2string(function_id)+RETURN_VALUE_SUFFIX;
374+
irep_idt rv_name = return_value_identifier(function_id, ns);
371375
const symbol_exprt &rhs=to_symbol_expr(assign.rhs());
372376
if(rhs.get_identifier()!=rv_name)
373377
continue;
@@ -409,3 +413,8 @@ void restore_returns(goto_modelt &goto_model)
409413
remove_returnst rr(goto_model.symbol_table);
410414
rr.restore(goto_model.goto_functions);
411415
}
416+
417+
irep_idt return_value_identifier(const irep_idt &identifier, const namespacet &)
418+
{
419+
return id2string(identifier) + RETURN_VALUE_SUFFIX;
420+
}

src/goto-programs/remove_returns.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,11 @@ Date: September 2009
7575

7676
#include <util/std_types.h>
7777

78-
#define RETURN_VALUE_SUFFIX "#return_value"
79-
8078
class goto_functionst;
8179
class goto_model_functiont;
8280
class goto_modelt;
8381
class symbol_table_baset;
82+
class namespacet;
8483

8584
void remove_returns(symbol_table_baset &, goto_functionst &);
8685

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

9695
void restore_returns(goto_modelt &);
9796

97+
/// produces the identifier that is used to store the return
98+
/// value of the function with the given identifier
99+
irep_idt return_value_identifier(const irep_idt &, const namespacet &);
100+
98101
#endif // CPROVER_GOTO_PROGRAMS_REMOVE_RETURNS_H

src/goto-programs/replace_calls.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ void replace_callst::operator()(
104104
const exprt &rhs = ca.rhs();
105105

106106
INVARIANT(
107-
rhs.id() != ID_symbol ||
108-
!has_suffix(
109-
id2string(to_symbol_expr(rhs).get_identifier()),
110-
RETURN_VALUE_SUFFIX),
107+
rhs.id() != ID_symbol || to_symbol_expr(rhs).get_identifier() !=
108+
return_value_identifier(id, ns),
111109
"returns must not be removed before replacing calls");
112110
}
113111

0 commit comments

Comments
 (0)