Skip to content

Commit 591764d

Browse files
committed
Linking: actually replace code type information in expressions
The linker already accepted a number of type mismatches for function declarations, but did not actually modify the goto functions to reflect these type mismatches, just the type information in the symbol table was updated.
1 parent e71e647 commit 591764d

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

regression/ansi-c/undeclared_function/undeclared_function1.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
fileA.c
33
fileB.c --validate-goto-model
44
^EXIT=0$

src/goto-programs/link_goto_model.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ static bool link_functions(
5858
goto_functionst &src_functions,
5959
const rename_symbolt &rename_symbol,
6060
const std::unordered_set<irep_idt> &weak_symbols,
61-
const replace_symbolt &object_type_updates)
61+
const replace_symbolt &object_type_updates,
62+
const replace_symbolt &code_type_updates)
6263
{
6364
namespacet ns(dest_symbol_table);
6465
namespacet src_ns(src_symbol_table);
@@ -163,6 +164,19 @@ static bool link_functions(
163164
}
164165
}
165166

167+
if(!code_type_updates.empty())
168+
{
169+
std::cerr << code_type_updates.get_expr_map().begin()->second.pretty() << std::endl;
170+
Forall_goto_functions(dest_it, dest_functions)
171+
Forall_goto_program_instructions(iit, dest_it->second.body)
172+
{
173+
code_type_updates(iit->code);
174+
175+
if(iit->has_condition())
176+
code_type_updates(iit->guard);
177+
}
178+
}
179+
166180
return false;
167181
}
168182

@@ -194,7 +208,8 @@ void link_goto_model(
194208
src.goto_functions,
195209
linking.rename_symbol,
196210
weak_symbols,
197-
linking.object_type_updates))
211+
linking.object_type_updates,
212+
linking.code_type_updates))
198213
{
199214
throw invalid_source_file_exceptiont("linking failed");
200215
}

src/linking/linking.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,12 @@ void linkingt::duplicate_code_symbol(
743743
}
744744
}
745745
}
746+
747+
if(old_symbol.type == new_symbol.type)
748+
{
749+
code_type_updates.insert(
750+
old_symbol.symbol_expr(), old_symbol.symbol_expr());
751+
}
746752
}
747753

748754
if(!new_symbol.value.is_nil())
@@ -757,6 +763,11 @@ void linkingt::duplicate_code_symbol(
757763
old_symbol.is_weak=new_symbol.is_weak;
758764
old_symbol.location=new_symbol.location;
759765
old_symbol.is_macro=new_symbol.is_macro;
766+
767+
// replace any previous update
768+
code_type_updates.erase(old_symbol.name);
769+
code_type_updates.insert(
770+
old_symbol.symbol_expr(), old_symbol.symbol_expr());
760771
}
761772
else if(to_code_type(old_symbol.type).get_inlined())
762773
{
@@ -1384,6 +1395,8 @@ void linkingt::copy_symbols()
13841395
{
13851396
object_type_updates(
13861397
main_symbol_table.get_writeable_ref(named_symbol.first).value);
1398+
code_type_updates(
1399+
main_symbol_table.get_writeable_ref(named_symbol.first).value);
13871400
}
13881401
}
13891402
}

src/linking/linking_class.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class linkingt:public typecheckt
4242

4343
rename_symbolt rename_symbol;
4444
casting_replace_symbolt object_type_updates;
45+
unchecked_replace_symbolt code_type_updates;
4546

4647
protected:
4748
bool needs_renaming_type(

0 commit comments

Comments
 (0)