Skip to content

Commit 1d4d551

Browse files
committed
Linking: fix up all types before handling functions or objects
Function parameters may require application of type fixes: our linking ensures that all types have a unique tag, and some parameter's types may require such tag updates. We used to do this for objects already, but need to apply it to parameters as well. Also, the order matters: all types need to be sorted out first before attempting objects or functions. Spotted while trying to compile a particular version of Xen 4.11.
1 parent 2e6200a commit 1d4d551

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

regression/ansi-c/linking_conflicts2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ main.c
33
other.c
44
^EXIT=(64|1)$
55
^SIGNAL=0$
6-
^\S+\.c(:\d+:\d+|\(\d+\)): error: conflicting function declarations 'foo'$
6+
^\S+\.c(:\d+:\d+|\(\d+\)): error: duplicate definition of function 'foo'$
77
--
88
^warning: ignoring

src/linking/linking.cpp

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,18 @@ void linkingt::duplicate_code_symbol(
215215
n_it!=new_t.parameters().end();
216216
++o_it, ++n_it)
217217
{
218-
if(o_it->type() != n_it->type())
218+
if(o_it->type() == n_it->type())
219+
continue;
220+
221+
adjust_type_infot info(old_symbol, new_symbol);
222+
bool failed = adjust_object_type_rec(o_it->type(), n_it->type(), info);
223+
replace = info.set_to_new;
224+
225+
if(failed)
226+
{
219227
conflicts.push_back(
220228
std::make_pair(o_it->type(), n_it->type()));
229+
}
221230
}
222231
if(o_it!=old_t.parameters().end())
223232
{
@@ -490,22 +499,20 @@ bool linkingt::adjust_object_type_rec(
490499
if(t1.id()==ID_pointer)
491500
{
492501
linking_diagnosticst diag{message_handler, ns};
493-
#if 0
494-
bool s=info.set_to_new;
495-
if(adjust_object_type_rec(t1.subtype(), t2.subtype(), info))
502+
if(info.old_symbol.type.id() == ID_code)
503+
{
504+
diag.warning(
505+
info.old_symbol,
506+
info.new_symbol,
507+
"pointer parameter types differ between declaration and definition");
508+
}
509+
else
496510
{
497511
diag.warning(
498512
info.old_symbol,
499513
info.new_symbol,
500514
"conflicting pointer types for variable");
501-
info.set_to_new=s;
502515
}
503-
#else
504-
diag.warning(
505-
info.old_symbol,
506-
info.new_symbol,
507-
"conflicting pointer types for variable");
508-
#endif
509516

510517
if(info.old_symbol.is_extern && !info.new_symbol.is_extern)
511518
{
@@ -1004,7 +1011,7 @@ void linkingt::copy_symbols(
10041011
}
10051012

10061013
// Move over all the non-colliding ones
1007-
std::unordered_set<irep_idt> collisions;
1014+
std::unordered_set<irep_idt> type_collisions, non_type_collisions;
10081015

10091016
for(const auto &named_symbol : src_symbols)
10101017
{
@@ -1021,21 +1028,27 @@ void linkingt::copy_symbols(
10211028
// new
10221029
main_symbol_table.add(named_symbol.second);
10231030
}
1031+
else if(named_symbol.second.is_type)
1032+
type_collisions.insert(named_symbol.first);
10241033
else
1025-
collisions.insert(named_symbol.first);
1034+
non_type_collisions.insert(named_symbol.first);
10261035
}
10271036
}
10281037

10291038
// Now do the collisions
1030-
for(const irep_idt &collision : collisions)
1039+
for(const irep_idt &collision : type_collisions)
10311040
{
10321041
symbolt &old_symbol = main_symbol_table.get_writeable_ref(collision);
10331042
symbolt &new_symbol=src_symbols.at(collision);
10341043

1035-
if(new_symbol.is_type)
1036-
duplicate_type_symbol(old_symbol, new_symbol);
1037-
else
1038-
duplicate_non_type_symbol(old_symbol, new_symbol);
1044+
duplicate_type_symbol(old_symbol, new_symbol);
1045+
}
1046+
for(const irep_idt &collision : non_type_collisions)
1047+
{
1048+
symbolt &old_symbol = main_symbol_table.get_writeable_ref(collision);
1049+
symbolt &new_symbol = src_symbols.at(collision);
1050+
1051+
duplicate_non_type_symbol(old_symbol, new_symbol);
10391052
}
10401053

10411054
// Apply type updates to initializers

0 commit comments

Comments
 (0)