Skip to content

Commit 5c18ccc

Browse files
committed
Type conflicts on the return value of implicitly declared functions are errors
1 parent d074537 commit 5c18ccc

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

regression/cbmc/return6/test.desc

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
f_def.c
4-
^EXIT=0$
4+
^EXIT=6$
55
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
6+
CONVERSION ERROR
77
--
88
^warning: ignoring
9+
^VERIFICATION SUCCESSFUL$

src/linking/linking.cpp

+24-11
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,23 @@ void linkingt::duplicate_code_symbol(
452452
const code_typet &old_t=to_code_type(old_symbol.type);
453453
const code_typet &new_t=to_code_type(new_symbol.type);
454454

455-
// if one of them was an implicit declaration, just issue a warning
455+
// if one of them was an implicit declaration then only conflicts on the
456+
// return type are an error as we would end up with assignments with
457+
// mismatching types; as we currently do not patch these by inserting type
458+
// casts we need to fail hard
456459
if(!old_symbol.location.get_function().empty() &&
457460
old_symbol.value.is_nil())
458461
{
459-
// issue a warning and overwrite
460-
link_warning(
461-
old_symbol,
462-
new_symbol,
463-
"implicit function declaration");
462+
if(base_type_eq(old_t.return_type(), new_t.return_type(), ns))
463+
link_warning(
464+
old_symbol,
465+
new_symbol,
466+
"implicit function declaration");
467+
else
468+
link_error(
469+
old_symbol,
470+
new_symbol,
471+
"implicit function declaration");
464472

465473
old_symbol.type=new_symbol.type;
466474
old_symbol.location=new_symbol.location;
@@ -469,11 +477,16 @@ void linkingt::duplicate_code_symbol(
469477
else if(!new_symbol.location.get_function().empty() &&
470478
new_symbol.value.is_nil())
471479
{
472-
// issue a warning
473-
link_warning(
474-
old_symbol,
475-
new_symbol,
476-
"ignoring conflicting implicit function declaration");
480+
if(base_type_eq(old_t.return_type(), new_t.return_type(), ns))
481+
link_warning(
482+
old_symbol,
483+
new_symbol,
484+
"ignoring conflicting implicit function declaration");
485+
else
486+
link_error(
487+
old_symbol,
488+
new_symbol,
489+
"implicit function declaration");
477490
}
478491
// handle (incomplete) function prototypes
479492
else if(base_type_eq(old_t.return_type(), new_t.return_type(), ns) &&

0 commit comments

Comments
 (0)