Skip to content

Commit 18db282

Browse files
author
Daniel Kroening
committed
remove_returns: ensure type consistency of return value assignment
1 parent a5f66f7 commit 18db282

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

regression/cbmc/Linking7/return_type.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
return_type1.c
33
return_type2.c
44
^EXIT=0$

src/goto-programs/remove_returns.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,13 @@ void remove_returnst::do_function_calls(
189189
exprt rhs;
190190

191191
if(!is_stub)
192-
rhs=return_value;
192+
{
193+
// The return type in the definition of the function may differ
194+
// from the return type in the declaration. We therefore do a
195+
// cast.
196+
rhs = typecast_exprt::conditional_cast(
197+
return_value, function_call.lhs().type());
198+
}
193199
else
194200
rhs = side_effect_expr_nondett(
195201
function_call.lhs().type(), i_it->source_location);
@@ -208,7 +214,7 @@ void remove_returnst::do_function_calls(
208214
goto_programt::targett t_d=goto_program.insert_after(t_a);
209215
t_d->make_dead();
210216
t_d->source_location=i_it->source_location;
211-
t_d->code=code_deadt(rhs);
217+
t_d->code = code_deadt(return_value);
212218
t_d->function=i_it->function;
213219
}
214220
}

0 commit comments

Comments
 (0)