Skip to content

Linking: fix up all types before handling functions or objects #7579

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion regression/ansi-c/linking_conflicts2/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ main.c
other.c
^EXIT=(64|1)$
^SIGNAL=0$
^\S+\.c(:\d+:\d+|\(\d+\)): error: conflicting function declarations 'foo'$
^\S+\.c(:\d+:\d+|\(\d+\)): error: duplicate definition of function 'foo'$
--
^warning: ignoring
49 changes: 31 additions & 18 deletions src/linking/linking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,18 @@ void linkingt::duplicate_code_symbol(
n_it!=new_t.parameters().end();
++o_it, ++n_it)
{
if(o_it->type() != n_it->type())
if(o_it->type() == n_it->type())
continue;

adjust_type_infot info(old_symbol, new_symbol);
bool failed = adjust_object_type_rec(o_it->type(), n_it->type(), info);
replace = info.set_to_new;

if(failed)
{
conflicts.push_back(
std::make_pair(o_it->type(), n_it->type()));
}
}
if(o_it!=old_t.parameters().end())
{
Expand Down Expand Up @@ -970,22 +979,20 @@ bool linkingt::adjust_object_type_rec(

if(t1.id()==ID_pointer)
{
#if 0
bool s=info.set_to_new;
if(adjust_object_type_rec(t1.subtype(), t2.subtype(), info))
if(info.old_symbol.type.id() == ID_code)
{
link_warning(
info.old_symbol,
info.new_symbol,
"pointer parameter types differ between declaration and definition");
}
else
{
link_warning(
info.old_symbol,
info.new_symbol,
"conflicting pointer types for variable");
info.set_to_new=s;
}
#else
link_warning(
info.old_symbol,
info.new_symbol,
"conflicting pointer types for variable");
#endif

if(info.old_symbol.is_extern && !info.new_symbol.is_extern)
{
Expand Down Expand Up @@ -1490,7 +1497,7 @@ void linkingt::copy_symbols(
}

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

for(const auto &named_symbol : src_symbols)
{
Expand All @@ -1507,21 +1514,27 @@ void linkingt::copy_symbols(
// new
main_symbol_table.add(named_symbol.second);
}
else if(named_symbol.second.is_type)
type_collisions.insert(named_symbol.first);
else
collisions.insert(named_symbol.first);
non_type_collisions.insert(named_symbol.first);
}
}

// Now do the collisions
for(const irep_idt &collision : collisions)
for(const irep_idt &collision : type_collisions)
{
symbolt &old_symbol = main_symbol_table.get_writeable_ref(collision);
symbolt &new_symbol=src_symbols.at(collision);

if(new_symbol.is_type)
duplicate_type_symbol(old_symbol, new_symbol);
else
duplicate_non_type_symbol(old_symbol, new_symbol);
duplicate_type_symbol(old_symbol, new_symbol);
}
for(const irep_idt &collision : non_type_collisions)
{
symbolt &old_symbol = main_symbol_table.get_writeable_ref(collision);
symbolt &new_symbol = src_symbols.at(collision);

duplicate_non_type_symbol(old_symbol, new_symbol);
}

// Apply type updates to initializers
Expand Down
Loading