Skip to content

Commit 08c7cdc

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 014188e commit 08c7cdc

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

regression/ansi-c/linking_conflicts2/test.desc

+1-1
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-
error: conflicting function declarations 'foo'
6+
error: duplicate definition of function 'foo'$
77
--
88
^warning: ignoring

src/linking/linking.cpp

+23-8
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,18 @@ void linkingt::duplicate_code_symbol(
678678
n_it!=new_t.parameters().end();
679679
++o_it, ++n_it)
680680
{
681-
if(o_it->type() != n_it->type())
681+
if(o_it->type() == n_it->type())
682+
continue;
683+
684+
adjust_type_infot info(old_symbol, new_symbol);
685+
bool failed = adjust_object_type_rec(o_it->type(), n_it->type(), info);
686+
replace = info.set_to_new;
687+
688+
if(failed)
689+
{
682690
conflicts.push_back(
683691
std::make_pair(o_it->type(), n_it->type()));
692+
}
684693
}
685694
if(o_it!=old_t.parameters().end())
686695
{
@@ -1460,7 +1469,7 @@ void linkingt::copy_symbols(
14601469
}
14611470

14621471
// Move over all the non-colliding ones
1463-
std::unordered_set<irep_idt> collisions;
1472+
std::unordered_set<irep_idt> type_collisions, non_type_collisions;
14641473

14651474
for(const auto &named_symbol : src_symbols)
14661475
{
@@ -1477,21 +1486,27 @@ void linkingt::copy_symbols(
14771486
// new
14781487
main_symbol_table.add(named_symbol.second);
14791488
}
1489+
else if(named_symbol.second.is_type)
1490+
type_collisions.insert(named_symbol.first);
14801491
else
1481-
collisions.insert(named_symbol.first);
1492+
non_type_collisions.insert(named_symbol.first);
14821493
}
14831494
}
14841495

14851496
// Now do the collisions
1486-
for(const irep_idt &collision : collisions)
1497+
for(const irep_idt &collision : type_collisions)
14871498
{
14881499
symbolt &old_symbol = main_symbol_table.get_writeable_ref(collision);
14891500
symbolt &new_symbol=src_symbols.at(collision);
14901501

1491-
if(new_symbol.is_type)
1492-
duplicate_type_symbol(old_symbol, new_symbol);
1493-
else
1494-
duplicate_non_type_symbol(old_symbol, new_symbol);
1502+
duplicate_type_symbol(old_symbol, new_symbol);
1503+
}
1504+
for(const irep_idt &collision : non_type_collisions)
1505+
{
1506+
symbolt &old_symbol = main_symbol_table.get_writeable_ref(collision);
1507+
symbolt &new_symbol = src_symbols.at(collision);
1508+
1509+
duplicate_non_type_symbol(old_symbol, new_symbol);
14951510
}
14961511

14971512
// Apply type updates to initializers

0 commit comments

Comments
 (0)