Skip to content

Commit 1d40d38

Browse files
Make goto_programt::instructiont::validate() accept differing return types
When a function declaration and its definition appear in different translation units they may have different return types. This commit relaxes the checks in goto_programt::instructiont::validate() in these circumstances.
1 parent 1447ad6 commit 1d40d38

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/goto-programs/goto_program.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,32 @@ void goto_programt::instructiont::validate(
726726
goto_symbol_expr.type(),
727727
original_return_type(ns.get_symbol_table(), goto_id),
728728
ns);
729+
730+
if(
731+
!symbol_expr_type_matches_symbol_table &&
732+
goto_symbol_expr.type().id() == ID_code)
733+
{
734+
// If a function declaration and its definition are in different
735+
// translation units they may have different return types,
736+
// which remove_returns patches up with a typecast. If thats
737+
// the case, then the return type in the symbol table may differ
738+
// from the return type in the symbol expr
739+
if(
740+
goto_symbol_expr.type().source_location().get_file() !=
741+
table_symbol->type.source_location().get_file())
742+
{
743+
// temporarily fixup the return types
744+
auto goto_symbol_expr_type =
745+
to_code_type(goto_symbol_expr.type());
746+
auto table_symbol_type = to_code_type(table_symbol->type);
747+
748+
goto_symbol_expr_type.return_type() =
749+
table_symbol_type.return_type();
750+
751+
symbol_expr_type_matches_symbol_table =
752+
base_type_eq(goto_symbol_expr_type, table_symbol_type, ns);
753+
}
754+
}
729755
}
730756

731757
if(

0 commit comments

Comments
 (0)