Skip to content

Commit 30145f5

Browse files
committed
Make --no-standard-checks reinstate old malloc behaviour
The calls to the `set_default_analysis_flags` functions need to be before the call to `config.set(cmdline)` so that the malloc defaults can be set before being overridden by any command line specified malloc behaviour.
1 parent 4f491d2 commit 30145f5

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

Diff for: src/cbmc/cbmc_parse_options.cpp

+18-5
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,28 @@ void cbmc_parse_optionst::set_default_analysis_flags(
121121
// Unwinding assertions required in certain cases for sound verification
122122
// results. See https://github.com/diffblue/cbmc/issues/6561 for elaboration.
123123
options.set_option("unwinding-assertions", enabled);
124+
125+
if(enabled)
126+
{
127+
config.ansi_c.malloc_may_fail = true;
128+
config.ansi_c.malloc_failure_mode =
129+
configt::ansi_ct::malloc_failure_modet::malloc_failure_mode_return_null;
130+
}
131+
else
132+
{
133+
config.ansi_c.malloc_may_fail = false;
134+
config.ansi_c.malloc_failure_mode =
135+
configt::ansi_ct::malloc_failure_modet::malloc_failure_mode_none;
136+
}
124137
}
125138

126139
void cbmc_parse_optionst::get_command_line_options(optionst &options)
127140
{
141+
// Enable flags that in combination provide analysis with no surprises
142+
// (expected checks and no unsoundness by missing checks).
143+
cbmc_parse_optionst::set_default_analysis_flags(
144+
options, !cmdline.isset("no-standard-checks"));
145+
128146
if(config.set(cmdline))
129147
{
130148
usage_error();
@@ -332,11 +350,6 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
332350
"self-loops-to-assumptions",
333351
!cmdline.isset("no-self-loops-to-assumptions"));
334352

335-
// Enable flags that in combination provide analysis with no surprises
336-
// (expected checks and no unsoundness by missing checks).
337-
cbmc_parse_optionst::set_default_analysis_flags(
338-
options, !cmdline.isset("no-standard-checks"));
339-
340353
// all (other) checks supported by goto_check
341354
PARSE_OPTIONS_GOTO_CHECK(cmdline, options);
342355

Diff for: src/goto-analyzer/goto_analyzer_parse_options.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,29 @@ void goto_analyzer_parse_optionst::set_default_analysis_flags(
6868
options.set_option("signed-overflow-check", enabled);
6969
options.set_option("undefined-shift-check", enabled);
7070

71+
if(enabled)
72+
{
73+
config.ansi_c.malloc_may_fail = true;
74+
config.ansi_c.malloc_failure_mode =
75+
configt::ansi_ct::malloc_failure_modet::malloc_failure_mode_return_null;
76+
}
77+
else
78+
{
79+
config.ansi_c.malloc_may_fail = false;
80+
config.ansi_c.malloc_failure_mode =
81+
configt::ansi_ct::malloc_failure_modet::malloc_failure_mode_none;
82+
}
83+
7184
// This is in-line with the options we set for CBMC in cbmc_parse_optionst
7285
// with the exception of unwinding-assertions, which don't make sense in
7386
// the context of abstract interpretation.
7487
}
7588

7689
void goto_analyzer_parse_optionst::get_command_line_options(optionst &options)
7790
{
91+
goto_analyzer_parse_optionst::set_default_analysis_flags(
92+
options, !cmdline.isset("no-standard-checks"));
93+
7894
if(config.set(cmdline))
7995
{
8096
usage_error();
@@ -84,9 +100,6 @@ void goto_analyzer_parse_optionst::get_command_line_options(optionst &options)
84100
if(cmdline.isset("function"))
85101
options.set_option("function", cmdline.get_value("function"));
86102

87-
goto_analyzer_parse_optionst::set_default_analysis_flags(
88-
options, !cmdline.isset("no-standard-checks"));
89-
90103
// all (other) checks supported by goto_check
91104
PARSE_OPTIONS_GOTO_CHECK(cmdline, options);
92105

0 commit comments

Comments
 (0)