Skip to content

Commit 32afaaa

Browse files
authored
Merge pull request #3089 from diffblue/test-for-issue-3081
simple test for mismatching return types accross compilation units
2 parents 432fb67 + 18db282 commit 32afaaa

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
return_type1.c
3+
return_type2.c
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Note issue #3081
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <assert.h>
2+
3+
struct S
4+
{
5+
int i;
6+
};
7+
8+
struct S *function();
9+
10+
int main()
11+
{
12+
assert(function() != 0);
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct S
2+
{
3+
int i;
4+
int j; // extra member
5+
} some_var;
6+
7+
struct S *function()
8+
{
9+
return &some_var;
10+
}

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)