-
Notifications
You must be signed in to change notification settings - Fork 277
Feature/internal invariant #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b290a9e
668dbfa
720e0f8
975b5a3
0a60788
0560b33
f77b843
cbe7de3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
int main() | ||
{ | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CORE | ||
main.c | ||
--test-invariant-failure | ||
^EXIT=(0|127|134|137)$ | ||
^SIGNAL=0$ | ||
Invariant check failed | ||
^(Backtrace)|(Backtraces not supported)$ | ||
-- | ||
^warning: ignoring | ||
^VERIFICATION SUCCESSFUL$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Author: Martin Brain, [email protected] | ||
|
||
#include <cassert> | ||
#include <assert.h> | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
assert(0); | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CORE | ||
main.cpp | ||
|
||
^main\.cpp:8: assert is deprecated, use INVARIANT instead \[build/deprecated\] \[4\] | ||
^Total errors found: 1$ | ||
^SIGNAL=0$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ Author: Daniel Kroening, [email protected] | |
#include <util/language.h> | ||
#include <util/unicode.h> | ||
#include <util/memory_info.h> | ||
#include <util/invariant.h> | ||
|
||
#include <ansi-c/c_preprocess.h> | ||
|
||
|
@@ -104,6 +105,27 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options) | |
exit(1); // should contemplate EX_USAGE from sysexits.h | ||
} | ||
|
||
// Test only; do not use for input validation | ||
if(cmdline.isset("test-invariant-failure")) | ||
{ | ||
// Have to catch this as the default handling of uncaught exceptions | ||
// on windows appears to be silent termination. | ||
try | ||
{ | ||
INVARIANT(0, "Test invariant failure"); | ||
} | ||
catch (const invariant_failedt &e) | ||
{ | ||
std::cerr << e.what(); | ||
exit(0); // should contemplate EX_OK from sysexits.h | ||
} | ||
catch (...) | ||
{ | ||
error() << "Unexpected exception type\n"; | ||
} | ||
exit(1); | ||
} | ||
|
||
if(cmdline.isset("program-only")) | ||
options.set_option("program-only", true); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected] | |
#include <util/ieee_float.h> | ||
#include <util/base_type.h> | ||
#include <util/string2int.h> | ||
#include <util/invariant.h> | ||
|
||
#include <ansi-c/string_constant.h> | ||
|
||
|
@@ -34,7 +35,6 @@ Author: Daniel Kroening, [email protected] | |
|
||
// Mark different kinds of error condition | ||
// General | ||
#define UNREACHABLE throw "Supposidly unreachable location reached" | ||
#define PARSERERROR(S) throw S | ||
|
||
// Error checking the expression type | ||
|
@@ -45,7 +45,7 @@ Author: Daniel Kroening, [email protected] | |
#define UNEXPECTEDCASE(S) throw "Unexpected case: " S | ||
|
||
// General todos | ||
#define TODO(S) throw "TODO: " S | ||
#define SMT2_TODO(S) throw "TODO: " S | ||
|
||
void smt2_convt::print_assignment(std::ostream &out) const | ||
{ | ||
|
@@ -952,7 +952,7 @@ void smt2_convt::convert_expr(const exprt &expr) | |
out << "))"; // mk-, let | ||
} | ||
else | ||
TODO("bitnot for vectors"); | ||
SMT2_TODO("bitnot for vectors"); | ||
} | ||
else | ||
{ | ||
|
@@ -1017,7 +1017,7 @@ void smt2_convt::convert_expr(const exprt &expr) | |
out << "))"; // mk-, let | ||
} | ||
else | ||
TODO("unary minus for vector"); | ||
SMT2_TODO("unary minus for vector"); | ||
} | ||
else | ||
{ | ||
|
@@ -1363,7 +1363,7 @@ void smt2_convt::convert_expr(const exprt &expr) | |
assert(expr.operands().size()==1); | ||
|
||
out << "false"; // TODO | ||
TODO("pointer_object_has_type not implemented"); | ||
SMT2_TODO("pointer_object_has_type not implemented"); | ||
} | ||
else if(expr.id()==ID_string_constant) | ||
{ | ||
|
@@ -1432,7 +1432,7 @@ void smt2_convt::convert_expr(const exprt &expr) | |
convert_expr(tmp); | ||
out << ")) bin1)"; // bvlshr, extract, = | ||
#endif | ||
TODO("smt2: extractbits with non-constant index"); | ||
SMT2_TODO("smt2: extractbits with non-constant index"); | ||
} | ||
} | ||
else if(expr.id()==ID_replication) | ||
|
@@ -1944,7 +1944,7 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr) | |
// This conversion is non-trivial as it requires creating a | ||
// new bit-vector variable and then asserting that it converts | ||
// to the required floating-point number. | ||
TODO("bit-wise floatbv to bv"); | ||
SMT2_TODO("bit-wise floatbv to bv"); | ||
} | ||
else | ||
{ | ||
|
@@ -2017,7 +2017,7 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr) | |
out << "(_ bv" << i << " " << to_width << ")"; | ||
} | ||
else | ||
TODO("can't convert non-constant integer to bitvector"); | ||
SMT2_TODO("can't convert non-constant integer to bitvector"); | ||
} | ||
else if(src_type.id()==ID_struct) // flatten a struct to a bit-vector | ||
{ | ||
|
@@ -2207,7 +2207,7 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr) | |
} | ||
else if(dest_type.id()==ID_range) | ||
{ | ||
TODO("range typecast"); | ||
SMT2_TODO("range typecast"); | ||
} | ||
else if(dest_type.id()==ID_floatbv) | ||
{ | ||
|
@@ -3031,11 +3031,11 @@ void smt2_convt::convert_floatbv_plus(const ieee_float_op_exprt &expr) | |
} | ||
else if(type.id()==ID_complex) | ||
{ | ||
TODO("+ for floatbv complex"); | ||
SMT2_TODO("+ for floatbv complex"); | ||
} | ||
else if(type.id()==ID_vector) | ||
{ | ||
TODO("+ for floatbv vector"); | ||
SMT2_TODO("+ for floatbv vector"); | ||
} | ||
else | ||
UNEXPECTEDCASE("unsupported type for +: "+type.id_string()); | ||
|
@@ -3093,7 +3093,7 @@ void smt2_convt::convert_minus(const minus_exprt &expr) | |
} | ||
else if(expr.type().id()==ID_pointer) | ||
{ | ||
TODO("pointer subtraction"); | ||
SMT2_TODO("pointer subtraction"); | ||
} | ||
else if(expr.type().id()==ID_vector) | ||
{ | ||
|
@@ -3527,7 +3527,7 @@ void smt2_convt::convert_with(const with_exprt &expr) | |
typecast_exprt index_tc(index, expr_type); | ||
|
||
// TODO: SMT2-ify | ||
TODO("SMT2-ify"); | ||
SMT2_TODO("SMT2-ify"); | ||
out << "(bvor "; | ||
out << "(band "; | ||
|
||
|
@@ -3565,7 +3565,7 @@ void smt2_convt::convert_update(const exprt &expr) | |
{ | ||
assert(expr.operands().size()==3); | ||
|
||
TODO("smt2_convt::convert_update to be implemented"); | ||
SMT2_TODO("smt2_convt::convert_update to be implemented"); | ||
} | ||
|
||
void smt2_convt::convert_index(const index_exprt &expr) | ||
|
@@ -3651,7 +3651,7 @@ void smt2_convt::convert_index(const index_exprt &expr) | |
mp_integer index_int; | ||
if(to_integer(expr.index(), index_int)) | ||
{ | ||
TODO("non-constant index on vectors"); | ||
SMT2_TODO("non-constant index on vectors"); | ||
} | ||
else | ||
{ | ||
|
@@ -3662,7 +3662,7 @@ void smt2_convt::convert_index(const index_exprt &expr) | |
} | ||
else | ||
{ | ||
TODO("index on vectors"); | ||
SMT2_TODO("index on vectors"); | ||
} | ||
} | ||
else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,13 @@ Author: Daniel Kroening, [email protected] | |
/// \file | ||
/// Expression Representation | ||
|
||
#include <cassert> | ||
|
||
#include <stack> | ||
|
||
#include "string2int.h" | ||
#include "mp_arith.h" | ||
#include "fixedbv.h" | ||
#include "ieee_float.h" | ||
#include "invariant.h" | ||
#include "expr.h" | ||
#include "rational.h" | ||
#include "rational_tools.h" | ||
|
@@ -203,15 +202,16 @@ void exprt::negate() | |
else | ||
{ | ||
make_nil(); | ||
assert(false); | ||
UNREACHABLE; | ||
} | ||
} | ||
else | ||
{ | ||
if(id()==ID_unary_minus) | ||
{ | ||
exprt tmp; | ||
assert(operands().size()==1); | ||
DATA_INVARIANT(operands().size()==1, | ||
"Unary minus must have one operand"); | ||
tmp.swap(op0()); | ||
swap(tmp); | ||
} | ||
|
@@ -245,7 +245,7 @@ bool exprt::is_zero() const | |
{ | ||
rationalt rat_value; | ||
if(to_rational(*this, rat_value)) | ||
assert(false); | ||
CHECK_RETURN(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would actually be even more convenient if we could write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes... this patch set is intended to replace assert but there are a few other invariant handling patterns that could benefit from some kind of support. This is one of them, another is: if (invariant) {
debug() << "Actually helpful message with " << variables << " in it "
<< "maybe even " << e.pretty();
assert(0);
} We should do something about these but I don't think we should do so in this patch set. I this will come out of trying to convert things to this way of doing things. We will get a better idea of what patterns there are and how they could be improved. |
||
return rat_value.is_zero(); | ||
} | ||
else if(type_id==ID_unsignedbv || | ||
|
@@ -291,7 +291,7 @@ bool exprt::is_one() const | |
{ | ||
rationalt rat_value; | ||
if(to_rational(*this, rat_value)) | ||
assert(false); | ||
CHECK_RETURN(false); | ||
return rat_value.is_one(); | ||
} | ||
else if(type_id==ID_unsignedbv || type_id==ID_signedbv) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not a TODO or UNIMPLEMENTED?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted this commit to be as minimal as possible and to be clearly not changing functionality (the whole set should be very low risk / minimal impact). To replace with the new TODO I'd have to move the more complex error messages to use error(), which would mean a bigger change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this can be done separately.