|
22 | 22 |
|
23 | 23 | #include <langapi/language_util.h>
|
24 | 24 |
|
| 25 | +#include "remove_returns.h" |
| 26 | + |
25 | 27 | /// Writes to \p out a two/three line string representation of a given
|
26 | 28 | /// \p instruction. The output is of the format:
|
27 | 29 | /// ```
|
@@ -709,13 +711,31 @@ void goto_programt::instructiont::validate(
|
709 | 711 | const auto &goto_id = goto_symbol_expr.get_identifier();
|
710 | 712 |
|
711 | 713 | 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 | + |
712 | 731 | DATA_CHECK_WITH_DIAGNOSTICS(
|
713 | 732 | vm,
|
714 |
| - base_type_eq(goto_symbol_expr.type(), table_symbol->type, ns), |
| 733 | + symbol_expr_type_matches_symbol_table, |
715 | 734 | id2string(goto_id) + " type inconsistency\n" +
|
716 | 735 | "goto program type: " + goto_symbol_expr.type().id_string() +
|
717 | 736 | "\n" + "symbol table type: " + table_symbol->type.id_string(),
|
718 | 737 | current_source_location);
|
| 738 | + } |
719 | 739 | }
|
720 | 740 | };
|
721 | 741 |
|
|
0 commit comments