Skip to content

Linking: report multiple conflicts #2027

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 1 commit into from
Apr 21, 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
14 changes: 14 additions & 0 deletions regression/ansi-c/linking_conflicts1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
int bar()
{
return 0;
}

int bar2()
{
return 0;
}

int main()
{
unsigned x = foo();
}
12 changes: 12 additions & 0 deletions regression/ansi-c/linking_conflicts1/other.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
void bar()
{
}

void bar2()
{
}

unsigned foo()
{
return 0;
}
10 changes: 10 additions & 0 deletions regression/ansi-c/linking_conflicts1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
other.c
^EXIT=(64|1)$
^SIGNAL=0$
^CONVERSION ERROR$
error: conflicting function declarations `bar'
error: conflicting function declarations `bar2'
--
^warning: ignoring
38 changes: 36 additions & 2 deletions src/linking/linking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,6 @@ void linkingt::link_error(
error() << "new definition in module `" << new_symbol.module
<< "' " << new_symbol.location << '\n'
<< type_to_string_verbose(ns, new_symbol) << eom;

throw 0;
}

void linkingt::link_warning(
Expand Down Expand Up @@ -573,6 +571,9 @@ void linkingt::duplicate_code_symbol(
old_symbol,
new_symbol,
"conflicting parameter counts of function declarations");

// error logged, continue typechecking other symbols
return;
}
else
{
Expand Down Expand Up @@ -602,19 +603,31 @@ void linkingt::duplicate_code_symbol(
if(o_it!=old_t.parameters().end())
{
if(!new_t.has_ellipsis() && old_symbol.value.is_not_nil())
{
link_error(
old_symbol,
new_symbol,
"conflicting parameter counts of function declarations");

// error logged, continue typechecking other symbols
return;
}

replace=new_symbol.value.is_not_nil();
}
else if(n_it!=new_t.parameters().end())
{
if(!old_t.has_ellipsis() && new_symbol.value.is_not_nil())
{
link_error(
old_symbol,
new_symbol,
"conflicting parameter counts of function declarations");

// error logged, continue typechecking other symbols
return;
}

replace=new_symbol.value.is_not_nil();
}

Expand Down Expand Up @@ -708,6 +721,9 @@ void linkingt::duplicate_code_symbol(
old_symbol,
new_symbol,
"conflicting function declarations");

// error logged, continue typechecking other symbols
return;
}
else
{
Expand Down Expand Up @@ -876,10 +892,15 @@ bool linkingt::adjust_object_type_rec(
equal_exprt eq(old_size, new_size);

if(!simplify_expr(eq, ns).is_true())
{
link_error(
info.old_symbol,
info.new_symbol,
"conflicting array sizes for variable");

// error logged, continue typechecking other symbols
return true;
}
}

return false;
Expand Down Expand Up @@ -958,6 +979,9 @@ void linkingt::duplicate_object_symbol(
old_symbol,
new_symbol,
"conflicting types for variable");

// error logged, continue typechecking other symbols
return;
}
else if(set_to_new)
old_symbol.type=new_symbol.type;
Expand Down Expand Up @@ -1022,11 +1046,16 @@ void linkingt::duplicate_non_type_symbol(
bool is_code_new_symbol=new_symbol.type.id()==ID_code;

if(is_code_old_symbol!=is_code_new_symbol)
{
link_error(
old_symbol,
new_symbol,
"conflicting definition for symbol");

// error logged, continue typechecking other symbols
return;
}

if(is_code_old_symbol)
duplicate_code_symbol(old_symbol, new_symbol);
else
Expand All @@ -1048,11 +1077,16 @@ void linkingt::duplicate_type_symbol(
assert(new_symbol.is_type);

if(!old_symbol.is_type)
{
link_error(
old_symbol,
new_symbol,
"conflicting definition for symbol");

// error logged, continue typechecking other symbols
return;
}

if(old_symbol.type==new_symbol.type)
return;

Expand Down