Skip to content

Commit 8558e89

Browse files
Petr BauchPetr Bauch
Petr Bauch
authored and
Petr Bauch
committed
Function type consistency between goto programs and symbol table
A simple iteration over goto-functions to check that it's base type is the same as the one stored in the symbol table.
1 parent 273f490 commit 8558e89

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/cbmc/cbmc_parse_options.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,10 @@ int cbmc_parse_optionst::doit()
515515
if(get_goto_program_ret!=-1)
516516
return get_goto_program_ret;
517517

518+
INVARIANT(
519+
!goto_model.check_internal_invariants(*this),
520+
"goto program internal invariants failed");
521+
518522
if(cmdline.isset("show-claims") || // will go away
519523
cmdline.isset("show-properties")) // use this one
520524
{

src/goto-programs/goto_model.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ Author: Daniel Kroening, [email protected]
1212
#ifndef CPROVER_GOTO_PROGRAMS_GOTO_MODEL_H
1313
#define CPROVER_GOTO_PROGRAMS_GOTO_MODEL_H
1414

15-
#include <util/symbol_table.h>
15+
#include <util/base_type.h>
1616
#include <util/journalling_symbol_table.h>
17+
#include <util/message.h>
18+
#include <util/symbol_table.h>
1719

1820
#include "abstract_goto_model.h"
1921
#include "goto_functions.h"
@@ -95,6 +97,27 @@ class goto_modelt : public abstract_goto_modelt
9597
return goto_functions.function_map.find(id) !=
9698
goto_functions.function_map.end();
9799
}
100+
101+
/// Iterates over the functions inside the goto model and checks invariants
102+
/// in all of them. Prints out error message collected.
103+
/// \param msg message instance to collect errors
104+
/// \return true if any violation was found
105+
bool check_internal_invariants(messaget &msg) const
106+
{
107+
bool found_violation = false;
108+
namespacet ns(symbol_table);
109+
forall_goto_functions(it, goto_functions)
110+
{
111+
if(!base_type_eq(
112+
it->second.type, symbol_table.lookup_ref(it->first).type, ns))
113+
{
114+
msg.error() << "error" << messaget::eom;
115+
found_violation = true;
116+
}
117+
}
118+
119+
return found_violation;
120+
}
98121
};
99122

100123
/// Class providing the abstract GOTO model interface onto an unrelated

0 commit comments

Comments
 (0)