Skip to content

Commit 720e0f8

Browse files
author
martin
committed
Add an (undocumented) option to test out what happens if an invariant fails.
1 parent 668dbfa commit 720e0f8

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int main()
2+
{
3+
return 0;
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--test-invariant-failure
4+
^EXIT=(0|127|134|137)$
5+
^SIGNAL=0$
6+
Invariant check failed
7+
^(Backtrace)|(Backtraces not supported)$
8+
--
9+
^warning: ignoring
10+
^VERIFICATION SUCCESSFUL$

src/cbmc/cbmc_parse_options.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Author: Daniel Kroening, kroening@kroening.com
1919
#include <util/language.h>
2020
#include <util/unicode.h>
2121
#include <util/memory_info.h>
22+
#include <util/invariant.h>
2223

2324
#include <ansi-c/c_preprocess.h>
2425

@@ -104,6 +105,27 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
104105
exit(1); // should contemplate EX_USAGE from sysexits.h
105106
}
106107

108+
// Test only; do not use for input validation
109+
if(cmdline.isset("test-invariant-failure"))
110+
{
111+
// Have to catch this as the default handling of uncaught exceptions
112+
// on windows appears to be silent termination.
113+
try
114+
{
115+
INVARIANT(0, "Test invariant failure");
116+
}
117+
catch (const invariant_failedt &e)
118+
{
119+
std::cerr << e.what();
120+
exit(0); // should contemplate EX_OK from sysexits.h
121+
}
122+
catch (...)
123+
{
124+
error() << "Unexpected exception type\n";
125+
}
126+
exit(1);
127+
}
128+
107129
if(cmdline.isset("program-only"))
108130
options.set_option("program-only", true);
109131

src/cbmc/cbmc_parse_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class optionst;
6363
"(java-cp-include-files):" \
6464
"(localize-faults)(localize-faults-method):" \
6565
"(lazy-methods)" \
66+
"(test-invariant-failure)" \
6667
"(fixedbv)(floatbv)(all-claims)(all-properties)" // legacy, and will eventually disappear // NOLINT(whitespace/line_length)
6768

6869
class cbmc_parse_optionst:

0 commit comments

Comments
 (0)