14
14
#include < ostream>
15
15
#include < iomanip>
16
16
17
+ #include < util/base_type.h>
17
18
#include < util/std_expr.h>
18
19
19
20
#include < langapi/language_util.h>
@@ -672,32 +673,36 @@ bool goto_programt::instructiont::check_internal_invariants(
672
673
const symbol_tablet &table,
673
674
messaget &msg) const
674
675
{
676
+ namespacet ns (table);
675
677
bool found_violation = false ;
676
- std::vector<std::string> id_collector ;
677
- auto symbol_finder = [&](const exprt &e) {
678
+ std::vector<std::vector<std:: string>> type_collector ;
679
+ auto type_finder = [&](const exprt &e) {
678
680
if (e.id () == ID_symbol)
679
681
{
680
682
auto symbol_expr = to_symbol_expr (e);
681
- if (!table.has_symbol (symbol_expr.get_identifier ()))
682
- id_collector.push_back (id2string (symbol_expr.get_identifier ()));
683
+ const auto &symbol_id = symbol_expr.get_identifier ();
684
+ if (
685
+ table.has_symbol (symbol_id) &&
686
+ !base_type_eq (symbol_expr.type (), table.lookup_ref (symbol_id).type , ns))
687
+ type_collector.push_back (
688
+ {id2string (symbol_id),
689
+ symbol_expr.type ().id_string (),
690
+ table.lookup_ref (symbol_id).type .id_string ()});
683
691
}
684
692
};
685
693
686
- if (!table.has_symbol (function))
687
- id_collector.push_back (id2string (function));
688
-
689
694
switch (type)
690
695
{
691
696
case GOTO:
692
697
case ASSUME:
693
698
case ASSERT:
694
- guard.visit (symbol_finder );
699
+ guard.visit (type_finder );
695
700
break ;
696
701
case ASSIGN:
697
702
case DECL:
698
703
case DEAD:
699
704
case FUNCTION_CALL:
700
- code.visit (symbol_finder );
705
+ code.visit (type_finder );
701
706
break ;
702
707
case OTHER:
703
708
case SKIP:
@@ -715,12 +720,15 @@ bool goto_programt::instructiont::check_internal_invariants(
715
720
break ;
716
721
}
717
722
718
- if (!id_collector .empty ())
723
+ if (!type_collector .empty ())
719
724
{
720
- for (const auto &id : id_collector )
725
+ for (const auto &type_triple : type_collector )
721
726
{
722
- msg.error () << id << " not found (" << source_location << " )"
723
- << messaget::eom;
727
+ INVARIANT (type_triple.size () > 2 , " should have 3 elements" );
728
+ msg.error () << type_triple[0 ] << " type inconsistency ("
729
+ << source_location << " )\n "
730
+ << " goto program type: " << type_triple[1 ] << " \n "
731
+ << " symbol table type: " << type_triple[2 ] << messaget::eom;
724
732
}
725
733
found_violation = true ;
726
734
}
0 commit comments