File tree Expand file tree Collapse file tree 9 files changed +57
-2
lines changed
regression/cbmc/havoc_undefined_functions Expand file tree Collapse file tree 9 files changed +57
-2
lines changed Original file line number Diff line number Diff line change
1
+ void function (int * a );
2
+
3
+ int main ()
4
+ {
5
+ int a = 0 ;
6
+ function (& a );
7
+ __CPROVER_assert (a == 0 , "" );
8
+ return 0 ;
9
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --havoc-undefined-functions
4
+ ^EXIT=10$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION FAILED$
Original file line number Diff line number Diff line change @@ -240,6 +240,9 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
240
240
if (cmdline.isset (" drop-unused-functions" ))
241
241
options.set_option (" drop-unused-functions" , true );
242
242
243
+ if (cmdline.isset (" havoc-undefined-functions" ))
244
+ options.set_option (" havoc-undefined-functions" , true );
245
+
243
246
if (cmdline.isset (" string-abstraction" ))
244
247
options.set_option (" string-abstraction" , true );
245
248
@@ -1082,6 +1085,9 @@ void cbmc_parse_optionst::help()
1082
1085
HELP_REACHABILITY_SLICER_FB
1083
1086
" --full-slice run full slicer (experimental)\n " // NOLINT(*)
1084
1087
" --drop-unused-functions drop functions trivially unreachable from main function\n " // NOLINT(*)
1088
+ " --havoc-undefined-functions\n "
1089
+ " for any function that has no body, assign non-deterministic values to\n " // NOLINT(*)
1090
+ " any parameters passed as non-const pointers and the return value\n " // NOLINT(*)
1085
1091
" \n "
1086
1092
" Semantic transformations:\n "
1087
1093
// NOLINTNEXTLINE(whitespace/line_length)
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ class optionst;
67
67
OPT_SHOW_PROPERTIES \
68
68
" (show-symbol-table)(show-parse-tree)" \
69
69
" (drop-unused-functions)" \
70
+ " (havoc-undefined-functions)" \
70
71
" (property):(stop-on-fail)(trace)" \
71
72
" (error-label):(verbosity):(no-library)" \
72
73
" (nondet-static)" \
Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ symex_bmct::symex_bmct(
33
33
path_storage,
34
34
guard_manager),
35
35
record_coverage(!options.get_option(" symex-coverage-report" ).empty()),
36
+ havoc_bodyless_functions(
37
+ options.get_bool_option(" havoc-undefined-functions" )),
36
38
symex_coverage(ns)
37
39
{
38
40
}
@@ -210,7 +212,13 @@ void symex_bmct::no_body(const irep_idt &identifier)
210
212
{
211
213
if (body_warnings.insert (identifier).second )
212
214
{
213
- log.warning () << " **** WARNING: no body for function " << identifier
214
- << log.eom ;
215
+ log.warning () << " **** WARNING: no body for function " << identifier;
216
+
217
+ if (havoc_bodyless_functions)
218
+ {
219
+ log.warning ()
220
+ << " ; assigning non-deterministic values to any pointer arguments" ;
221
+ }
222
+ log.warning () << log.eom ;
215
223
}
216
224
}
Original file line number Diff line number Diff line change @@ -81,6 +81,7 @@ class symex_bmct : public goto_symext
81
81
}
82
82
83
83
const bool record_coverage;
84
+ const bool havoc_bodyless_functions;
84
85
85
86
unwindsett unwindset;
86
87
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ struct symex_configt final
34
34
35
35
bool partial_loops;
36
36
37
+ bool havoc_undefined_functions;
38
+
37
39
mp_integer debug_level;
38
40
39
41
// / \brief Should the additional validation checks be run?
Original file line number Diff line number Diff line change 11
11
12
12
#include " goto_symex.h"
13
13
14
+ #include < analyses/guard_expr.h>
14
15
#include < util/arith_tools.h>
15
16
#include < util/byte_operators.h>
16
17
#include < util/c_types.h>
@@ -293,6 +294,25 @@ void goto_symext::symex_function_call_code(
293
294
symex_assign (state, code);
294
295
}
295
296
297
+ if (symex_config.havoc_undefined_functions )
298
+ {
299
+ // assign non det to function arguments if pointers
300
+ // are not const
301
+ for (const auto &arg : call.arguments ())
302
+ {
303
+ if (
304
+ arg.type ().id () == ID_pointer &&
305
+ !arg.type ().subtype ().get_bool (ID_C_constant) &&
306
+ arg.type ().subtype ().id () != ID_code)
307
+ {
308
+ exprt object = dereference_exprt (arg, arg.type ().subtype ());
309
+ exprt cleaned_object = clean_expr (object, state, true );
310
+ const guardt guard (true_exprt (), state.guard_manager );
311
+ havoc_rec (state, guard, cleaned_object);
312
+ }
313
+ }
314
+ }
315
+
296
316
symex_transition (state);
297
317
return ;
298
318
}
Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ symex_configt::symex_configt(const optionst &options)
42
42
simplify_opt(options.get_bool_option(" simplify" )),
43
43
unwinding_assertions(options.get_bool_option(" unwinding-assertions" )),
44
44
partial_loops(options.get_bool_option(" partial-loops" )),
45
+ havoc_undefined_functions(
46
+ options.get_bool_option(" havoc-undefined-functions" )),
45
47
debug_level(unsafe_string2int(options.get_option(" debug-level" ))),
46
48
run_validation_checks(options.get_bool_option(" validate-ssa-equation" )),
47
49
show_symex_steps(options.get_bool_option(" show-goto-symex-steps" )),
You can’t perform that action at this time.
0 commit comments