Skip to content

Commit 16e2a14

Browse files
committed
Unify the remove-returns query
between goto-program/remove-return and the respective validation check. Update the unit-test accordingly.
1 parent a88a188 commit 16e2a14

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

src/goto-programs/remove_returns.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,7 @@ bool remove_returnst::do_function_calls(
162162
to_symbol_expr(function_call.function()).get_identifier();
163163

164164
// Do we return anything?
165-
if(
166-
to_code_type(function_call.function().type()).return_type() !=
167-
empty_typet() &&
168-
function_call.lhs().is_not_nil())
165+
if(does_function_call_return(function_call))
169166
{
170167
// replace "lhs=f(...)" by
171168
// "f(...); lhs=f#return_value; DEAD f#return_value;"
@@ -430,3 +427,10 @@ bool is_return_value_symbol(const symbol_exprt &symbol_expr)
430427
{
431428
return is_return_value_identifier(symbol_expr.get_identifier());
432429
}
430+
431+
bool does_function_call_return(const code_function_callt &function_call)
432+
{
433+
return to_code_type(function_call.function().type()).return_type() !=
434+
empty_typet() &&
435+
function_call.lhs().is_not_nil();
436+
}

src/goto-programs/remove_returns.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Date: September 2009
7373

7474
#include <functional>
7575

76+
#include <util/std_code.h>
7677
#include <util/std_types.h>
7778

7879
class goto_functionst;
@@ -111,4 +112,9 @@ bool is_return_value_identifier(const irep_idt &id);
111112
/// \ref return_value_symbol
112113
bool is_return_value_symbol(const symbol_exprt &symbol_expr);
113114

115+
/// Check if the \p function_call returns anything
116+
/// \param function_call: the function call to be investigated
117+
/// \return true if non-void return type and non-nil lhs
118+
bool does_function_call_return(const code_function_callt &function_call);
119+
114120
#endif // CPROVER_GOTO_PROGRAMS_REMOVE_RETURNS_H

src/goto-programs/validate_goto_model.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Date: Oct 2018
1414
#include <util/invariant.h>
1515

1616
#include "goto_functions.h"
17+
#include "remove_returns.h"
1718

1819
namespace
1920
{
@@ -132,7 +133,7 @@ void validate_goto_modelt::check_returns_removed()
132133
const auto &function_call = instr.get_function_call();
133134
DATA_CHECK(
134135
vm,
135-
function_call.lhs().is_nil(),
136+
!does_function_call_return(function_call),
136137
"function call lhs return should be nil");
137138
}
138139
}

unit/goto-programs/goto_program_validate.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,11 @@ SCENARIO("Validation of a goto program", "[core][goto-programs][validate]")
217217

218218
WHEN("not all returns have been removed - a function call lhs is not nil")
219219
{
220+
// int h();
220221
symbolt h;
221222
h.name = "h";
222223
h.mode = ID_C;
223-
h.type = code_typet({}, empty_typet{});
224+
h.type = code_typet({}, signed_int_type());
224225
h.value = code_blockt{};
225226
goto_model.symbol_table.add(h);
226227

0 commit comments

Comments
 (0)