Skip to content

Commit 1da5faa

Browse files
committed
[WIP] Enable default flags on for checks
1 parent 52688d7 commit 1da5faa

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

src/ansi-c/goto_check_c.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,21 @@ void goto_check_c(
7979

8080
// clang-format off
8181
#define PARSE_OPTIONS_GOTO_CHECK(cmdline, options) \
82-
options.set_option("bounds-check", cmdline.isset("bounds-check")); \
83-
options.set_option("pointer-check", cmdline.isset("pointer-check")); \
82+
options.set_option("bounds-check", !cmdline.isset("no-bounds-check")); \
83+
options.set_option("pointer-check", !cmdline.isset("no-pointer-check")); \
8484
options.set_option("memory-leak-check", cmdline.isset("memory-leak-check")); \
8585
options.set_option("memory-cleanup-check", cmdline.isset("memory-cleanup-check")); /* NOLINT(whitespace/line_length) */ \
86-
options.set_option("div-by-zero-check", cmdline.isset("div-by-zero-check")); \
86+
options.set_option("div-by-zero-check", !cmdline.isset("no-div-by-zero-check")); \
8787
options.set_option("enum-range-check", cmdline.isset("enum-range-check")); \
88-
options.set_option("signed-overflow-check", cmdline.isset("signed-overflow-check")); /* NOLINT(whitespace/line_length) */ \
88+
options.set_option("signed-overflow-check", !cmdline.isset("no-signed-overflow-check")); /* NOLINT(whitespace/line_length) */ \
8989
options.set_option("unsigned-overflow-check", cmdline.isset("unsigned-overflow-check")); /* NOLINT(whitespace/line_length) */ \
9090
options.set_option("pointer-overflow-check", cmdline.isset("pointer-overflow-check")); /* NOLINT(whitespace/line_length) */ \
9191
options.set_option("conversion-check", cmdline.isset("conversion-check")); \
92-
options.set_option("undefined-shift-check", cmdline.isset("undefined-shift-check")); /* NOLINT(whitespace/line_length) */ \
92+
options.set_option("undefined-shift-check", !cmdline.isset("no-undefined-shift-check")); /* NOLINT(whitespace/line_length) */ \
9393
options.set_option("float-overflow-check", cmdline.isset("float-overflow-check")); /* NOLINT(whitespace/line_length) */ \
9494
options.set_option("nan-check", cmdline.isset("nan-check")); \
9595
options.set_option("built-in-assertions", !cmdline.isset("no-built-in-assertions")); /* NOLINT(whitespace/line_length) */ \
96-
options.set_option("pointer-primitive-check", cmdline.isset("pointer-primitive-check")); /* NOLINT(whitespace/line_length) */ \
96+
options.set_option("pointer-primitive-check", !cmdline.isset("no-pointer-primitive-check")); /* NOLINT(whitespace/line_length) */ \
9797
options.set_option("retain-trivial-checks", \
9898
cmdline.isset("retain-trivial-checks")); \
9999
options.set_option("assertions", !cmdline.isset("no-assertions")); /* NOLINT(whitespace/line_length) */ \

src/cbmc/cbmc_parse_options.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ ::cbmc_parse_optionst::cbmc_parse_optionst(
9393

9494
void cbmc_parse_optionst::set_default_options(optionst &options)
9595
{
96+
// Enable the standard checks by default, unless a user overrides.
97+
options.set_option("standard-checks", true);
98+
9699
// Default true
97100
options.set_option("built-in-assertions", true);
98101
options.set_option("propagation", true);
@@ -107,6 +110,20 @@ void cbmc_parse_optionst::set_default_options(optionst &options)
107110
options.set_option("depth", UINT32_MAX);
108111
}
109112

113+
void cbmc_parse_optionst::set_soundness_on_by_default(optionst &options)
114+
{
115+
// Analysis flags on by default
116+
options.set_option("bounds-check", true);
117+
options.set_option("pointer-check", true);
118+
options.set_option("pointer-primitive-check", true);
119+
options.set_option("malloc-may-fail", true);
120+
// TODO: Default malloc-fail-profile
121+
options.set_option("div-by-zero-check", true);
122+
options.set_option("signed-overflow-check", true);
123+
options.set_option("undefined-shift-check", true);
124+
options.set_option("unwinding-assertions", true);
125+
}
126+
110127
void cbmc_parse_optionst::get_command_line_options(optionst &options)
111128
{
112129
if(config.set(cmdline))
@@ -118,6 +135,11 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
118135
cbmc_parse_optionst::set_default_options(options);
119136
parse_c_object_factory_options(cmdline, options);
120137

138+
// Enable flags that in combination provide analysis with no surprises
139+
// (expected checks and no unsoundness by missing checks).
140+
if (options.get_bool_option("standard-checks"))
141+
set_soundness_on_by_default(options);
142+
121143
if(cmdline.isset("function"))
122144
options.set_option("function", cmdline.get_value("function"));
123145

@@ -310,8 +332,14 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
310332
PARSE_OPTIONS_GOTO_CHECK(cmdline, options);
311333

312334
// generate unwinding assertions
313-
if(cmdline.isset("unwinding-assertions"))
335+
// TODO: Fotis: revisit
336+
if(cmdline.isset("no-unwinding-assertions"))
314337
{
338+
options.set_option("unwinding-assertions", false);
339+
options.set_option("paths-symex-explore-all", false);
340+
} else {
341+
// Not really needed, as it's now on by default, but keeping it here
342+
// for completeness' sake.
315343
options.set_option("unwinding-assertions", true);
316344
options.set_option("paths-symex-explore-all", true);
317345
}

src/cbmc/cbmc_parse_options.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class optionst;
3333

3434
// clang-format off
3535
#define CBMC_OPTIONS \
36-
OPT_BMC \
36+
OPT_BMC \
37+
"(standard-checks)" \
3738
"(preprocess)(slice-by-trace):" \
3839
OPT_FUNCTIONS \
3940
"(no-simplify)(full-slice)" \
@@ -90,6 +91,7 @@ class cbmc_parse_optionst : public parse_options_baset
9091
/// This function can be called from clients that wish to emulate CBMC's
9192
/// default behaviour, for example unit tests.
9293
static void set_default_options(optionst &);
94+
static void set_soundness_on_by_default(optionst &options);
9395

9496
static bool process_goto_program(goto_modelt &, const optionst &, messaget &);
9597

0 commit comments

Comments
 (0)