Skip to content

Return value removal: handle missing declarations more gracefully #5671

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 1 commit into from
Nov 15, 2022
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
18 changes: 18 additions & 0 deletions regression/cbmc/return7/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
void a()
{
// Uses the implicit signature of undefined functions: int c(void)
int b;
b = c();
__CPROVER_assert(b == 0, "expected to fail");
}
void c(void)
{
// Actually... don't return anything
// So the results will be non-deterministic
}

int main(int argc, char **argv)
{
a();
return 0;
}
9 changes: 9 additions & 0 deletions regression/cbmc/return7/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c

^VERIFICATION FAILED$
^EXIT=10$
^SIGNAL=0$
--
Reason: Check return value
^warning: ignoring
20 changes: 20 additions & 0 deletions src/goto-programs/builtin_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,16 @@ void goto_convertt::do_function_call_symbol(
code_function_callt function_call(lhs, function, arguments);
function_call.add_source_location() = function.source_location();

// remove void-typed assignments, which may have been created when the
// front-end was unable to detect them in type checking for a lack of
// available declarations
if(
lhs.is_not_nil() &&
to_code_type(symbol->type).return_type().id() == ID_empty)
{
function_call.lhs().make_nil();
}

copy(function_call, FUNCTION_CALL, dest);

return;
Expand Down Expand Up @@ -1435,6 +1445,16 @@ void goto_convertt::do_function_call_symbol(
code_function_callt function_call(lhs, function, arguments);
function_call.add_source_location()=function.source_location();

// remove void-typed assignments, which may have been created when the
// front-end was unable to detect them in type checking for a lack of
// available declarations
if(
lhs.is_not_nil() &&
to_code_type(symbol->type).return_type().id() == ID_empty)
{
function_call.lhs().make_nil();
}

copy(function_call, FUNCTION_CALL, dest);
}
}
6 changes: 3 additions & 3 deletions src/goto-programs/remove_returns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ bool remove_returnst::do_function_calls(
optionalt<symbol_exprt> return_value;

if(!is_stub)
{
return_value = get_or_create_return_value_symbol(function_id);
CHECK_RETURN(return_value.has_value());

if(return_value.has_value())
{
// The return type in the definition of the function may differ
// from the return type in the declaration. We therefore do a
// cast.
Expand All @@ -199,7 +199,7 @@ bool remove_returnst::do_function_calls(
// fry the previous assignment
i_it->call_lhs().make_nil();

if(!is_stub)
if(return_value.has_value())
{
goto_program.insert_after(
t_a,
Expand Down