Skip to content

Commit 14bc277

Browse files
committed
Add is_return_value_* methods
Now that RETURN_VALUE_SUFFIX is hidden, these provide a way to easily differentiate an ordinary global variable from one introduced by remove_returns.
1 parent 0a28dd1 commit 14bc277

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

src/goto-programs/remove_returns.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Date: September 2009
1414
#include "remove_returns.h"
1515

1616
#include <util/std_expr.h>
17+
#include <util/suffix.h>
1718

1819
#include "goto_model.h"
1920

@@ -419,3 +420,13 @@ return_value_symbol(const irep_idt &identifier, const namespacet &ns)
419420
const typet &return_type = to_code_type(function_symbol.type).return_type();
420421
return symbol_exprt(return_value_identifier(identifier), return_type);
421422
}
423+
424+
bool is_return_value_identifier(const irep_idt &id)
425+
{
426+
return has_suffix(id2string(id), RETURN_VALUE_SUFFIX);
427+
}
428+
429+
bool is_return_value_symbol(const symbol_exprt &symbol_expr)
430+
{
431+
return is_return_value_identifier(symbol_expr.get_identifier());
432+
}

src/goto-programs/remove_returns.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,12 @@ irep_idt return_value_identifier(const irep_idt &);
103103
/// value of the function with the given identifier
104104
symbol_exprt return_value_symbol(const irep_idt &, const namespacet &);
105105

106+
/// Returns true if \p id is a special return-value symbol produced by
107+
/// \ref return_value_identifier
108+
bool is_return_value_identifier(const irep_idt &id);
109+
110+
/// Returns true if \p symbol_expr is a special return-value symbol produced by
111+
/// \ref return_value_symbol
112+
bool is_return_value_symbol(const symbol_exprt &symbol_expr);
113+
106114
#endif // CPROVER_GOTO_PROGRAMS_REMOVE_RETURNS_H

unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ SRC += analyses/ai/ai.cpp \
2727
goto-programs/goto_program_table_consistency.cpp \
2828
goto-programs/goto_program_validate.cpp \
2929
goto-programs/goto_trace_output.cpp \
30+
goto-programs/remove_returns.cpp \
3031
goto-programs/xml_expr.cpp \
3132
goto-symex/ssa_equation.cpp \
3233
goto-symex/is_constant.cpp \

unit/goto-programs/remove_returns.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for remove_returns
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#include <testing-utils/use_catch.h>
10+
11+
#include <goto-programs/remove_returns.h>
12+
#include <util/namespace.h>
13+
#include <util/std_expr.h>
14+
#include <util/std_types.h>
15+
#include <util/symbol_table.h>
16+
17+
TEST_CASE(
18+
"Return-value removal",
19+
"[core][goto-programs][remove_returns]")
20+
{
21+
symbol_tablet symbol_table;
22+
symbolt function_symbol;
23+
function_symbol.name = "a";
24+
function_symbol.pretty_name = "a";
25+
function_symbol.base_name = "a";
26+
function_symbol.type = code_typet({}, signedbv_typet(32));
27+
28+
symbol_table.add(function_symbol);
29+
30+
namespacet ns(symbol_table);
31+
32+
symbol_exprt a_rv_symbol = return_value_symbol("a", ns);
33+
REQUIRE(is_return_value_symbol(a_rv_symbol));
34+
REQUIRE(is_return_value_identifier(a_rv_symbol.get_identifier()));
35+
36+
irep_idt a_rv_id = return_value_identifier("a");
37+
38+
REQUIRE(is_return_value_identifier(a_rv_id));
39+
40+
symbol_exprt other_symbol("a::local", signedbv_typet(8));
41+
REQUIRE(!is_return_value_symbol(other_symbol));
42+
REQUIRE(!is_return_value_identifier(other_symbol.get_identifier()));
43+
}

0 commit comments

Comments
 (0)