Skip to content

Commit 43052d5

Browse files
Petr BauchPetr Bauch
Petr Bauch
authored and
Petr Bauch
committed
Reworked based on PR diffblue#3123
Using DATA_CHECK instead of calling error handling directly.
1 parent 7dd2aa5 commit 43052d5

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

src/cbmc/cbmc_parse_options.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,6 @@ 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-
522518
if(cmdline.isset("show-claims") || // will go away
523519
cmdline.isset("show-properties")) // use this one
524520
{
@@ -530,6 +526,12 @@ int cbmc_parse_optionst::doit()
530526
if(set_properties())
531527
return CPROVER_EXIT_SET_PROPERTIES_FAILED;
532528

529+
if(cmdline.isset("validate-goto-model"))
530+
{
531+
namespacet ns(goto_model.symbol_table);
532+
goto_model.validate(ns, validation_modet::INVARIANT);
533+
}
534+
533535
return bmct::do_language_agnostic_bmc(
534536
path_strategy_chooser, options, goto_model, ui_message_handler);
535537
}
@@ -976,6 +978,7 @@ void cbmc_parse_optionst::help()
976978
" --xml-ui use XML-formatted output\n"
977979
" --xml-interface bi-directional XML interface\n"
978980
" --json-ui use JSON-formatted output\n"
981+
" --validate-goto-model enables additional well-formedness checks on the goto program\n" // NOLINT(*)
979982
HELP_GOTO_TRACE
980983
HELP_FLUSH
981984
" --verbosity # verbosity level\n"

src/cbmc/cbmc_parse_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class optionst;
7272
OPT_FLUSH \
7373
"(localize-faults)(localize-faults-method):" \
7474
OPT_GOTO_TRACE \
75+
"(validate-goto-model)" \
7576
"(claim):(show-claims)(floatbv)(all-claims)(all-properties)" // legacy, and will eventually disappear // NOLINT(whitespace/line_length)
7677
// clang-format on
7778

src/goto-programs/goto_model.h

+9-19
Original file line numberDiff line numberDiff line change
@@ -100,29 +100,19 @@ class goto_modelt : public abstract_goto_modelt
100100

101101
/// Iterates over the functions inside the goto model and checks invariants
102102
/// 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
103+
/// \param ns namespace for the environment
104+
/// \param vm validation mode to be used for error reporting
105+
void validate(const namespacet &ns, const validation_modet &vm) const
106106
{
107-
bool found_violation = false;
108-
namespacet ns(symbol_table);
109107
forall_goto_functions(it, goto_functions)
110108
{
111-
if(!base_type_eq(
112-
it->second.type, symbol_table.lookup_ref(it->first).type, ns))
113-
{
114-
msg.error() << id2string(it->first) << " type inconsistency\n"
115-
<< "goto program type: " << it->second.type.id_string()
116-
<< "\nsymbol table type: "
117-
<< symbol_table.lookup_ref(it->first).type.id_string()
118-
<< messaget::eom;
119-
120-
msg.error() << "" << messaget::eom;
121-
found_violation = true;
122-
}
109+
DATA_CHECK(
110+
base_type_eq(
111+
it->second.type, symbol_table.lookup_ref(it->first).type, ns),
112+
id2string(it->first) + " type inconsistency\ngoto program type: " +
113+
it->second.type.id_string() + "\nsymbol table type: " +
114+
symbol_table.lookup_ref(it->first).type.id_string());
123115
}
124-
125-
return found_violation;
126116
}
127117
};
128118

src/util/expr.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Daniel Kroening, [email protected]
1010
#define CPROVER_UTIL_EXPR_H
1111

1212
#include "type.h"
13+
#include "validate.h"
1314

1415
#include <functional>
1516
#include <list>

0 commit comments

Comments
 (0)