Skip to content

Commit 523fed3

Browse files
committed
Return value removal: handle missing declarations more gracefully
If a function is used before it is defined, a signature of int f(void) is assumed. Then trying to use the (possibly non-existent) return value fails during return-statement removal. In such cases, just assume a non-deterministic value is being returned. Found by running C-Reduce on a CSmith-generated example.
1 parent fd8af8a commit 523fed3

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

regression/cbmc/return7/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
void a()
2+
{
3+
int b = c();
4+
}
5+
void c(void)
6+
{
7+
}

regression/cbmc/return7/test.desc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
4+
the program has no entry point
5+
^EXIT=6$
6+
^SIGNAL=0$
7+
--
8+
Reason: Check return value
9+
^warning: ignoring
10+
^VERIFICATION SUCCESSFUL$

src/goto-programs/remove_returns.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ bool remove_returnst::do_function_calls(
174174
optionalt<symbol_exprt> return_value;
175175

176176
if(!is_stub)
177-
{
178177
return_value = get_or_create_return_value_symbol(function_id);
179-
CHECK_RETURN(return_value.has_value());
180178

179+
if(return_value.has_value())
180+
{
181181
// The return type in the definition of the function may differ
182182
// from the return type in the declaration. We therefore do a
183183
// cast.
@@ -198,7 +198,7 @@ bool remove_returnst::do_function_calls(
198198
// fry the previous assignment
199199
function_call.lhs().make_nil();
200200

201-
if(!is_stub)
201+
if(return_value.has_value())
202202
{
203203
goto_program.insert_after(
204204
t_a,

0 commit comments

Comments
 (0)