Skip to content

Commit f6dc117

Browse files
Correct symbol table type check in cases where return removal has modified types
Return removal sets the return type of a function symbol table entry to 'void', but some callsites still expect the original type (e.g. if a function is passed as a parameter to a different function)
1 parent 33be524 commit f6dc117

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/goto-programs/goto_program.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Author: Daniel Kroening, [email protected]
2222

2323
#include <langapi/language_util.h>
2424

25+
#include "remove_returns.h"
26+
2527
/// Writes to \p out a two/three line string representation of a given
2628
/// \p instruction. The output is of the format:
2729
/// ```
@@ -709,13 +711,31 @@ void goto_programt::instructiont::validate(
709711
const auto &goto_id = goto_symbol_expr.get_identifier();
710712

711713
if(!ns.lookup(goto_id, table_symbol))
714+
{
715+
bool symbol_expr_type_matches_symbol_table =
716+
base_type_eq(goto_symbol_expr.type(), table_symbol->type, ns);
717+
718+
if(
719+
!symbol_expr_type_matches_symbol_table &&
720+
table_symbol->type.id() == ID_code)
721+
{
722+
// Return removal sets the return type of a function symbol table
723+
// entry to 'void', but some callsites still expect the original
724+
// type (e.g. if a function is passed as a parameter)
725+
symbol_expr_type_matches_symbol_table = base_type_eq(
726+
goto_symbol_expr.type(),
727+
original_return_type(ns.get_symbol_table(), goto_id),
728+
ns);
729+
}
730+
712731
DATA_CHECK_WITH_DIAGNOSTICS(
713732
vm,
714-
base_type_eq(goto_symbol_expr.type(), table_symbol->type, ns),
733+
symbol_expr_type_matches_symbol_table,
715734
id2string(goto_id) + " type inconsistency\n" +
716735
"goto program type: " + goto_symbol_expr.type().id_string() +
717736
"\n" + "symbol table type: " + table_symbol->type.id_string(),
718737
current_source_location);
738+
}
719739
}
720740
};
721741

0 commit comments

Comments
 (0)