Skip to content

Commit 40f038a

Browse files
Petr BauchPetr Bauch
authored andcommitted
Check base types of symbol expressions in goto programs
Look up the symbol id in symbol table and call base_type_eq on every symbol expression in guard and code whenever relevant. Print out all inconsistencies.
1 parent efb95a6 commit 40f038a

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/goto-programs/goto_program.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414
#include <ostream>
1515
#include <iomanip>
1616

17+
#include <util/base_type.h>
1718
#include <util/std_expr.h>
1819

1920
#include <langapi/language_util.h>
@@ -672,32 +673,36 @@ bool goto_programt::instructiont::check_internal_invariants(
672673
const symbol_tablet &table,
673674
messaget &msg) const
674675
{
676+
namespacet ns(table);
675677
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) {
678680
if(e.id() == ID_symbol)
679681
{
680682
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()});
683691
}
684692
};
685693

686-
if(!table.has_symbol(function))
687-
id_collector.push_back(id2string(function));
688-
689694
switch(type)
690695
{
691696
case GOTO:
692697
case ASSUME:
693698
case ASSERT:
694-
guard.visit(symbol_finder);
699+
guard.visit(type_finder);
695700
break;
696701
case ASSIGN:
697702
case DECL:
698703
case DEAD:
699704
case FUNCTION_CALL:
700-
code.visit(symbol_finder);
705+
code.visit(type_finder);
701706
break;
702707
case OTHER:
703708
case SKIP:
@@ -715,12 +720,15 @@ bool goto_programt::instructiont::check_internal_invariants(
715720
break;
716721
}
717722

718-
if(!id_collector.empty())
723+
if(!type_collector.empty())
719724
{
720-
for(const auto &id : id_collector)
725+
for(const auto &type_triple : type_collector)
721726
{
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;
724732
}
725733
found_violation = true;
726734
}

0 commit comments

Comments
 (0)