Skip to content

Commit 20fc8d1

Browse files
author
Daniel Kroening
authored
Merge pull request diffblue#1363 from diffblue/undeclared-return-conflict
test for signature conflict with undeclared function
2 parents 92b4873 + 5c18ccc commit 20fc8d1

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

regression/cbmc/return6/f_def.c

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
unsigned f()
2+
{
3+
return 0x34;
4+
}

regression/cbmc/return6/main.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <assert.h>
2+
3+
// Do not declare f().
4+
// This is invalid from C99 upwards, but kind of ok before.
5+
6+
int main()
7+
{
8+
int return_value;
9+
return_value=f();
10+
assert(return_value==0x34);
11+
}

regression/cbmc/return6/test.desc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
f_def.c
4+
^EXIT=6$
5+
^SIGNAL=0$
6+
CONVERSION ERROR
7+
--
8+
^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)