Skip to content

Commit 1597b39

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 8fe2acf commit 1597b39

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
@@ -738,6 +738,32 @@ void goto_programt::instructiont::validate(
738738
symbol_expr_type_matches_symbol_table = base_type_eq(
739739
goto_symbol_expr.type(), full_table_symbol_type, ns);
740740
}
741+
742+
if(
743+
!symbol_expr_type_matches_symbol_table &&
744+
goto_symbol_expr.type().id() == ID_code)
745+
{
746+
// If a function declaration and its definition are in different
747+
// translation units they may have different return types,
748+
// which remove_returns patches up with a typecast. If thats
749+
// the case, then the return type in the symbol table may differ
750+
// from the return type in the symbol expr
751+
if(
752+
goto_symbol_expr.type().source_location().get_file() !=
753+
table_symbol->type.source_location().get_file())
754+
{
755+
// temporarily fixup the return types
756+
auto goto_symbol_expr_type =
757+
to_code_type(goto_symbol_expr.type());
758+
auto table_symbol_type = to_code_type(table_symbol->type);
759+
760+
goto_symbol_expr_type.return_type() =
761+
table_symbol_type.return_type();
762+
763+
symbol_expr_type_matches_symbol_table =
764+
base_type_eq(goto_symbol_expr_type, table_symbol_type, ns);
765+
}
766+
}
741767
}
742768

743769
if(

0 commit comments

Comments
 (0)