Skip to content

test for signature conflict with undeclared function #1363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions regression/cbmc/return6/f_def.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
unsigned f()
{
return 0x34;
}
11 changes: 11 additions & 0 deletions regression/cbmc/return6/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <assert.h>

// Do not declare f().
// This is invalid from C99 upwards, but kind of ok before.

int main()
{
int return_value;
return_value=f();
assert(return_value==0x34);
}
9 changes: 9 additions & 0 deletions regression/cbmc/return6/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
f_def.c
^EXIT=6$
^SIGNAL=0$
CONVERSION ERROR
--
^warning: ignoring
^VERIFICATION SUCCESSFUL$
35 changes: 24 additions & 11 deletions src/linking/linking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,23 @@ void linkingt::duplicate_code_symbol(
const code_typet &old_t=to_code_type(old_symbol.type);
const code_typet &new_t=to_code_type(new_symbol.type);

// if one of them was an implicit declaration, just issue a warning
// if one of them was an implicit declaration then only conflicts on the
// return type are an error as we would end up with assignments with
// mismatching types; as we currently do not patch these by inserting type
// casts we need to fail hard
if(!old_symbol.location.get_function().empty() &&
old_symbol.value.is_nil())
{
// issue a warning and overwrite
link_warning(
old_symbol,
new_symbol,
"implicit function declaration");
if(base_type_eq(old_t.return_type(), new_t.return_type(), ns))
link_warning(
old_symbol,
new_symbol,
"implicit function declaration");
else
link_error(
old_symbol,
new_symbol,
"implicit function declaration");

old_symbol.type=new_symbol.type;
old_symbol.location=new_symbol.location;
Expand All @@ -469,11 +477,16 @@ void linkingt::duplicate_code_symbol(
else if(!new_symbol.location.get_function().empty() &&
new_symbol.value.is_nil())
{
// issue a warning
link_warning(
old_symbol,
new_symbol,
"ignoring conflicting implicit function declaration");
if(base_type_eq(old_t.return_type(), new_t.return_type(), ns))
link_warning(
old_symbol,
new_symbol,
"ignoring conflicting implicit function declaration");
else
link_error(
old_symbol,
new_symbol,
"implicit function declaration");
}
// handle (incomplete) function prototypes
else if(base_type_eq(old_t.return_type(), new_t.return_type(), ns) &&
Expand Down