Skip to content

Commit f3bbb12

Browse files
committed
Linking: report multiple conflicts
Previously, linking would fail with an exception upon the first symbol with conflicting types. As there may be multiple problems found in the same linking run, display all conflicts to the user so that they can fix all of them at once.
1 parent da63652 commit f3bbb12

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
int bar()
2+
{
3+
return 0;
4+
}
5+
6+
int bar2()
7+
{
8+
return 0;
9+
}
10+
11+
int main()
12+
{
13+
unsigned x = foo();
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void bar()
2+
{
3+
}
4+
5+
void bar2()
6+
{
7+
}
8+
9+
unsigned foo()
10+
{
11+
return 0;
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
other.c
4+
^EXIT=(64|1)$
5+
^SIGNAL=0$
6+
^CONVERSION ERROR$
7+
error: conflicting function declarations `bar'
8+
error: conflicting function declarations `bar2'
9+
--
10+
^warning: ignoring

src/linking/linking.cpp

+36-2
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,6 @@ void linkingt::link_error(
382382
error() << "new definition in module `" << new_symbol.module
383383
<< "' " << new_symbol.location << '\n'
384384
<< type_to_string_verbose(ns, new_symbol) << eom;
385-
386-
throw 0;
387385
}
388386

389387
void linkingt::link_warning(
@@ -573,6 +571,9 @@ void linkingt::duplicate_code_symbol(
573571
old_symbol,
574572
new_symbol,
575573
"conflicting parameter counts of function declarations");
574+
575+
// error logged, continue typechecking other symbols
576+
return;
576577
}
577578
else
578579
{
@@ -602,19 +603,31 @@ void linkingt::duplicate_code_symbol(
602603
if(o_it!=old_t.parameters().end())
603604
{
604605
if(!new_t.has_ellipsis() && old_symbol.value.is_not_nil())
606+
{
605607
link_error(
606608
old_symbol,
607609
new_symbol,
608610
"conflicting parameter counts of function declarations");
611+
612+
// error logged, continue typechecking other symbols
613+
return;
614+
}
615+
609616
replace=new_symbol.value.is_not_nil();
610617
}
611618
else if(n_it!=new_t.parameters().end())
612619
{
613620
if(!old_t.has_ellipsis() && new_symbol.value.is_not_nil())
621+
{
614622
link_error(
615623
old_symbol,
616624
new_symbol,
617625
"conflicting parameter counts of function declarations");
626+
627+
// error logged, continue typechecking other symbols
628+
return;
629+
}
630+
618631
replace=new_symbol.value.is_not_nil();
619632
}
620633

@@ -708,6 +721,9 @@ void linkingt::duplicate_code_symbol(
708721
old_symbol,
709722
new_symbol,
710723
"conflicting function declarations");
724+
725+
// error logged, continue typechecking other symbols
726+
return;
711727
}
712728
else
713729
{
@@ -876,10 +892,15 @@ bool linkingt::adjust_object_type_rec(
876892
equal_exprt eq(old_size, new_size);
877893

878894
if(!simplify_expr(eq, ns).is_true())
895+
{
879896
link_error(
880897
info.old_symbol,
881898
info.new_symbol,
882899
"conflicting array sizes for variable");
900+
901+
// error logged, continue typechecking other symbols
902+
return true;
903+
}
883904
}
884905

885906
return false;
@@ -958,6 +979,9 @@ void linkingt::duplicate_object_symbol(
958979
old_symbol,
959980
new_symbol,
960981
"conflicting types for variable");
982+
983+
// error logged, continue typechecking other symbols
984+
return;
961985
}
962986
else if(set_to_new)
963987
old_symbol.type=new_symbol.type;
@@ -1022,11 +1046,16 @@ void linkingt::duplicate_non_type_symbol(
10221046
bool is_code_new_symbol=new_symbol.type.id()==ID_code;
10231047

10241048
if(is_code_old_symbol!=is_code_new_symbol)
1049+
{
10251050
link_error(
10261051
old_symbol,
10271052
new_symbol,
10281053
"conflicting definition for symbol");
10291054

1055+
// error logged, continue typechecking other symbols
1056+
return;
1057+
}
1058+
10301059
if(is_code_old_symbol)
10311060
duplicate_code_symbol(old_symbol, new_symbol);
10321061
else
@@ -1048,11 +1077,16 @@ void linkingt::duplicate_type_symbol(
10481077
assert(new_symbol.is_type);
10491078

10501079
if(!old_symbol.is_type)
1080+
{
10511081
link_error(
10521082
old_symbol,
10531083
new_symbol,
10541084
"conflicting definition for symbol");
10551085

1086+
// error logged, continue typechecking other symbols
1087+
return;
1088+
}
1089+
10561090
if(old_symbol.type==new_symbol.type)
10571091
return;
10581092

0 commit comments

Comments
 (0)