Skip to content

Add is_return_value_* methods #4637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/goto-programs/remove_returns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Date: September 2009
#include "remove_returns.h"

#include <util/std_expr.h>
#include <util/suffix.h>

#include "goto_model.h"

Expand Down Expand Up @@ -419,3 +420,13 @@ return_value_symbol(const irep_idt &identifier, const namespacet &ns)
const typet &return_type = to_code_type(function_symbol.type).return_type();
return symbol_exprt(return_value_identifier(identifier), return_type);
}

bool is_return_value_identifier(const irep_idt &id)
{
return has_suffix(id2string(id), RETURN_VALUE_SUFFIX);
}

bool is_return_value_symbol(const symbol_exprt &symbol_expr)
{
return is_return_value_identifier(symbol_expr.get_identifier());
}
8 changes: 8 additions & 0 deletions src/goto-programs/remove_returns.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,12 @@ irep_idt return_value_identifier(const irep_idt &);
/// value of the function with the given identifier
symbol_exprt return_value_symbol(const irep_idt &, const namespacet &);

/// Returns true if \p id is a special return-value symbol produced by
/// \ref return_value_identifier
bool is_return_value_identifier(const irep_idt &id);

/// Returns true if \p symbol_expr is a special return-value symbol produced by
/// \ref return_value_symbol
bool is_return_value_symbol(const symbol_exprt &symbol_expr);

#endif // CPROVER_GOTO_PROGRAMS_REMOVE_RETURNS_H
1 change: 1 addition & 0 deletions unit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ SRC += analyses/ai/ai.cpp \
goto-programs/goto_program_table_consistency.cpp \
goto-programs/goto_program_validate.cpp \
goto-programs/goto_trace_output.cpp \
goto-programs/remove_returns.cpp \
goto-programs/xml_expr.cpp \
goto-symex/ssa_equation.cpp \
goto-symex/is_constant.cpp \
Expand Down
41 changes: 41 additions & 0 deletions unit/goto-programs/remove_returns.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*******************************************************************\

Module: Unit tests for remove_returns

Author: Diffblue Ltd.

\*******************************************************************/

#include <testing-utils/use_catch.h>

#include <goto-programs/remove_returns.h>
#include <util/namespace.h>
#include <util/std_expr.h>
#include <util/std_types.h>
#include <util/symbol_table.h>

TEST_CASE("Return-value removal", "[core][goto-programs][remove_returns]")
{
symbol_tablet symbol_table;
symbolt function_symbol;
function_symbol.name = "a";
function_symbol.pretty_name = "a";
function_symbol.base_name = "a";
function_symbol.type = code_typet({}, signedbv_typet(32));

symbol_table.add(function_symbol);

namespacet ns(symbol_table);

symbol_exprt a_rv_symbol = return_value_symbol("a", ns);
REQUIRE(is_return_value_symbol(a_rv_symbol));
REQUIRE(is_return_value_identifier(a_rv_symbol.get_identifier()));

irep_idt a_rv_id = return_value_identifier("a");

REQUIRE(is_return_value_identifier(a_rv_id));

symbol_exprt other_symbol("a::local", signedbv_typet(8));
REQUIRE(!is_return_value_symbol(other_symbol));
REQUIRE(!is_return_value_identifier(other_symbol.get_identifier()));
}