Skip to content

Commit e616881

Browse files
authored
Merge pull request #6687 from tautschnig/cleanup/assertions-assumptions-filter
goto_check_ct: Transforming assertions and assumptions is language-agnostic
2 parents b88797c + f9e2dc8 commit e616881

File tree

8 files changed

+127
-75
lines changed

8 files changed

+127
-75
lines changed

jbmc/src/janalyzer/janalyzer_parse_options.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -703,13 +703,7 @@ void janalyzer_parse_optionst::process_goto_function(
703703

704704
remove_returns(function, function_is_stub);
705705

706-
// add generic checks
707-
goto_check(
708-
function.get_function_id(),
709-
function.get_goto_function(),
710-
ns,
711-
options,
712-
ui_message_handler);
706+
transform_assertions_assumptions(options, function.get_goto_function().body);
713707
}
714708

715709
bool janalyzer_parse_optionst::can_generate_function_body(const irep_idt &name)

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,13 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "jbmc_parse_options.h"
1313

14-
#include <cstdlib> // exit()
15-
#include <iostream>
16-
#include <memory>
17-
1814
#include <util/config.h>
1915
#include <util/exit_codes.h>
2016
#include <util/invariant.h>
2117
#include <util/make_unique.h>
2218
#include <util/version.h>
2319
#include <util/xml.h>
2420

25-
#include <langapi/language.h>
26-
27-
#include <ansi-c/ansi_c_language.h>
28-
29-
#include <goto-checker/all_properties_verifier.h>
30-
#include <goto-checker/all_properties_verifier_with_fault_localization.h>
31-
#include <goto-checker/all_properties_verifier_with_trace_storage.h>
32-
#include <goto-checker/stop_on_fail_verifier.h>
33-
#include <goto-checker/stop_on_fail_verifier_with_fault_localization.h>
34-
3521
#include <goto-programs/adjust_float_expressions.h>
3622
#include <goto-programs/goto_convert_functions.h>
3723
#include <goto-programs/instrument_preconditions.h>
@@ -45,18 +31,17 @@ Author: Daniel Kroening, [email protected]
4531
#include <goto-programs/show_properties.h>
4632
#include <goto-programs/show_symbol_table.h>
4733

34+
#include <analyses/goto_check.h>
35+
#include <ansi-c/ansi_c_language.h>
36+
#include <goto-checker/all_properties_verifier.h>
37+
#include <goto-checker/all_properties_verifier_with_fault_localization.h>
38+
#include <goto-checker/all_properties_verifier_with_trace_storage.h>
39+
#include <goto-checker/stop_on_fail_verifier.h>
40+
#include <goto-checker/stop_on_fail_verifier_with_fault_localization.h>
4841
#include <goto-instrument/full_slicer.h>
4942
#include <goto-instrument/nondet_static.h>
5043
#include <goto-instrument/reachability_slicer.h>
51-
5244
#include <goto-symex/path_storage.h>
53-
54-
#include <linking/static_lifetime_init.h>
55-
56-
#include <pointer-analysis/add_failed_symbols.h>
57-
58-
#include <langapi/mode.h>
59-
6045
#include <java_bytecode/convert_java_nondet.h>
6146
#include <java_bytecode/java_bytecode_language.h>
6247
#include <java_bytecode/java_multi_path_symex_checker.h>
@@ -69,6 +54,14 @@ Author: Daniel Kroening, [email protected]
6954
#include <java_bytecode/remove_java_new.h>
7055
#include <java_bytecode/replace_java_nondet.h>
7156
#include <java_bytecode/simple_method_stubbing.h>
57+
#include <langapi/language.h>
58+
#include <langapi/mode.h>
59+
#include <linking/static_lifetime_init.h>
60+
#include <pointer-analysis/add_failed_symbols.h>
61+
62+
#include <cstdlib> // exit()
63+
#include <iostream>
64+
#include <memory>
7265

7366
jbmc_parse_optionst::jbmc_parse_optionst(int argc, const char **argv)
7467
: parse_options_baset(
@@ -717,13 +710,7 @@ void jbmc_parse_optionst::process_goto_function(
717710
ui_message_handler);
718711
}
719712

720-
// add generic checks
721-
goto_check_java(
722-
function.get_function_id(),
723-
function.get_goto_function(),
724-
ns,
725-
options,
726-
ui_message_handler);
713+
transform_assertions_assumptions(options, function.get_goto_function().body);
727714

728715
// Replace Java new side effects
729716
remove_java_new(

jbmc/src/jdiff/jdiff_parse_options.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ Author: Peter Schrammel
1111

1212
#include "jdiff_parse_options.h"
1313

14-
#include <cstdlib> // exit()
15-
#include <iostream>
16-
1714
#include <util/config.h>
1815
#include <util/exit_codes.h>
1916
#include <util/options.h>
@@ -31,15 +28,18 @@ Author: Peter Schrammel
3128
#include <goto-programs/set_properties.h>
3229
#include <goto-programs/show_properties.h>
3330

31+
#include <analyses/goto_check.h>
32+
#include <goto-diff/change_impact.h>
33+
#include <goto-diff/unified_diff.h>
3434
#include <goto-instrument/cover.h>
35-
3635
#include <java_bytecode/java_bytecode_language.h>
3736
#include <java_bytecode/remove_exceptions.h>
3837
#include <java_bytecode/remove_instanceof.h>
3938

4039
#include "java_syntactic_diff.h"
41-
#include <goto-diff/change_impact.h>
42-
#include <goto-diff/unified_diff.h>
40+
41+
#include <cstdlib> // exit()
42+
#include <iostream>
4343

4444
jdiff_parse_optionst::jdiff_parse_optionst(int argc, const char **argv)
4545
: parse_options_baset(
@@ -190,9 +190,7 @@ bool jdiff_parse_optionst::process_goto_program(
190190
// remove returns
191191
remove_returns(goto_model);
192192

193-
// add generic checks
194-
log.status() << "Generic Property Instrumentation" << messaget::eom;
195-
goto_check_java(options, goto_model, ui_message_handler);
193+
transform_assertions_assumptions(options, goto_model);
196194

197195
// checks don't know about adjusted float expressions
198196
adjust_float_expressions(goto_model);

src/analyses/goto_check.cpp

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "goto_check.h"
1313

14-
#include "goto_check_c.h"
15-
14+
#include <util/options.h>
1615
#include <util/symbol.h>
1716

17+
#include <goto-programs/goto_model.h>
18+
#include <goto-programs/remove_skip.h>
19+
20+
#include "goto_check_c.h"
21+
1822
void goto_check(
1923
const irep_idt &function_identifier,
2024
goto_functionst::goto_functiont &goto_function,
@@ -47,3 +51,84 @@ void goto_check(
4751
{
4852
goto_check_c(options, goto_model, message_handler);
4953
}
54+
55+
static void transform_assertions_assumptions(
56+
goto_programt &goto_program,
57+
bool enable_assertions,
58+
bool enable_built_in_assertions,
59+
bool enable_assumptions)
60+
{
61+
bool did_something = false;
62+
63+
for(auto &instruction : goto_program.instructions)
64+
{
65+
if(instruction.is_assert())
66+
{
67+
bool is_user_provided =
68+
instruction.source_location().get_bool("user-provided");
69+
70+
if(
71+
(is_user_provided && !enable_assertions &&
72+
instruction.source_location().get_property_class() != "error label") ||
73+
(!is_user_provided && !enable_built_in_assertions))
74+
{
75+
instruction.turn_into_skip();
76+
did_something = true;
77+
}
78+
}
79+
else if(instruction.is_assume())
80+
{
81+
if(!enable_assumptions)
82+
{
83+
instruction.turn_into_skip();
84+
did_something = true;
85+
}
86+
}
87+
}
88+
89+
if(did_something)
90+
remove_skip(goto_program);
91+
}
92+
93+
void transform_assertions_assumptions(
94+
const optionst &options,
95+
goto_modelt &goto_model)
96+
{
97+
const bool enable_assertions = options.get_bool_option("assertions");
98+
const bool enable_built_in_assertions =
99+
options.get_bool_option("built-in-assertions");
100+
const bool enable_assumptions = options.get_bool_option("assumptions");
101+
102+
// check whether there could possibly be anything to do
103+
if(enable_assertions && enable_built_in_assertions && enable_assumptions)
104+
return;
105+
106+
for(auto &entry : goto_model.goto_functions.function_map)
107+
{
108+
transform_assertions_assumptions(
109+
entry.second.body,
110+
enable_assertions,
111+
enable_built_in_assertions,
112+
enable_assumptions);
113+
}
114+
}
115+
116+
void transform_assertions_assumptions(
117+
const optionst &options,
118+
goto_programt &goto_program)
119+
{
120+
const bool enable_assertions = options.get_bool_option("assertions");
121+
const bool enable_built_in_assertions =
122+
options.get_bool_option("built-in-assertions");
123+
const bool enable_assumptions = options.get_bool_option("assumptions");
124+
125+
// check whether there could possibly be anything to do
126+
if(enable_assertions && enable_built_in_assertions && enable_assumptions)
127+
return;
128+
129+
transform_assertions_assumptions(
130+
goto_program,
131+
enable_assertions,
132+
enable_built_in_assertions,
133+
enable_assumptions);
134+
}

src/analyses/goto_check.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,18 @@ void goto_check(
3434

3535
void goto_check(const optionst &, goto_modelt &, message_handlert &);
3636

37+
/// Handle the options "assertions", "built-in-assertions", "assumptions" to
38+
/// remove assertions and assumptions in \p goto_model when these are set to
39+
/// false in \p options.
40+
void transform_assertions_assumptions(
41+
const optionst &options,
42+
goto_modelt &goto_model);
43+
44+
/// Handle the options "assertions", "built-in-assertions", "assumptions" to
45+
/// remove assertions and assumptions in \p goto_program when these are set to
46+
/// false in \p options.
47+
void transform_assertions_assumptions(
48+
const optionst &options,
49+
goto_programt &goto_program);
50+
3751
#endif // CPROVER_ANALYSES_GOTO_CHECK_H

src/analyses/goto_check_c.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ class goto_check_ct
7474
enable_nan_check = _options.get_bool_option("nan-check");
7575
retain_trivial = _options.get_bool_option("retain-trivial-checks");
7676
enable_assert_to_assume = _options.get_bool_option("assert-to-assume");
77-
enable_assertions = _options.get_bool_option("assertions");
78-
enable_built_in_assertions =
79-
_options.get_bool_option("built-in-assertions");
80-
enable_assumptions = _options.get_bool_option("assumptions");
8177
error_labels = _options.get_list_option("error-label");
8278
enable_pointer_primitive_check =
8379
_options.get_bool_option("pointer-primitive-check");
@@ -274,9 +270,6 @@ class goto_check_ct
274270
bool enable_nan_check;
275271
bool retain_trivial;
276272
bool enable_assert_to_assume;
277-
bool enable_assertions;
278-
bool enable_built_in_assertions;
279-
bool enable_assumptions;
280273
bool enable_pointer_primitive_check;
281274

282275
/// Maps a named-check name to the corresponding boolean flag.
@@ -2173,27 +2166,6 @@ void goto_check_ct::goto_check(
21732166
// this has no successor
21742167
assertions.clear();
21752168
}
2176-
else if(i.is_assert())
2177-
{
2178-
bool is_user_provided = i.source_location().get_bool("user-provided");
2179-
2180-
if(
2181-
(is_user_provided && !enable_assertions &&
2182-
i.source_location().get_property_class() != "error label") ||
2183-
(!is_user_provided && !enable_built_in_assertions))
2184-
{
2185-
i.turn_into_skip();
2186-
did_something = true;
2187-
}
2188-
}
2189-
else if(i.is_assume())
2190-
{
2191-
if(!enable_assumptions)
2192-
{
2193-
i.turn_into_skip();
2194-
did_something = true;
2195-
}
2196-
}
21972169
else if(i.is_dead())
21982170
{
21992171
if(enable_pointer_check || enable_pointer_primitive_check)

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,7 @@ void goto_instrument_parse_optionst::instrument_goto_program()
13311331

13321332
// add generic checks, if needed
13331333
goto_check(options, goto_model, ui_message_handler);
1334+
transform_assertions_assumptions(options, goto_model);
13341335

13351336
// check for uninitalized local variables
13361337
if(cmdline.isset("uninitialized-check"))

src/goto-programs/process_goto_program.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ bool process_goto_program(
7474
// add generic checks
7575
log.status() << "Generic Property Instrumentation" << messaget::eom;
7676
goto_check(options, goto_model, log.get_message_handler());
77+
transform_assertions_assumptions(options, goto_model);
7778

7879
// checks don't know about adjusted float expressions
7980
adjust_float_expressions(goto_model);

0 commit comments

Comments
 (0)