38
38
#include < ansi-c/goto-conversion/link_to_library.h>
39
39
#include < goto-instrument/contracts/cfg_info.h>
40
40
#include < goto-instrument/contracts/utils.h>
41
+ #include < goto-instrument/generate_function_bodies.h>
41
42
#include < goto-instrument/nondet_static.h>
42
43
#include < langapi/language.h>
43
44
#include < langapi/language_file.h>
@@ -492,21 +493,6 @@ void dfcct::transform_goto_model()
492
493
493
494
library.inhibit_front_end_builtins ();
494
495
495
- // TODO implement a means to inhibit unreachable functions (possibly via the
496
- // code that implements drop-unused-functions followed by
497
- // generate-function-bodies):
498
- // Traverse the call tree from the given entry point to identify
499
- // functions symbols that are effectively called in the model,
500
- // Then goes over all functions of the model and turns the bodies of all
501
- // functions that are not in the used function set into:
502
- // ```c
503
- // assert(false, "function identified as unreachable");
504
- // assume(false);
505
- // ```
506
- // That way, if the analysis mistakenly pruned some functions, assertions
507
- // will be violated and the analysis will fail.
508
- // TODO: add a command line flag to tell the instrumentation to not prune
509
- // a function.
510
496
goto_model.goto_functions .update ();
511
497
512
498
remove_skip (goto_model);
@@ -516,11 +502,25 @@ void dfcct::transform_goto_model()
516
502
517
503
// This can prune too many functions if function pointers have not been
518
504
// yet been removed or if the entry point is not defined.
519
- // Another solution would be to rewrite the bodies of functions that seem to
520
- // be unreachable into assert(false);assume(false)
505
+ // TODO: add a command line flag to tell the instrumentation to not prune
506
+ // a function.
521
507
remove_unused_functions (goto_model, message_handler);
522
508
goto_model.goto_functions .update ();
523
509
510
+ // generate assert(0); assume(0); function bodies for all functions missing an
511
+ // implementation (other than ones containing __CPROVER in their name)
512
+ auto generate_implementation = generate_function_bodies_factory (
513
+ " assert-false-assume-false" ,
514
+ c_object_factory_parameterst{},
515
+ goto_model.symbol_table ,
516
+ message_handler);
517
+ generate_function_bodies (
518
+ std::regex (" (?!" CPROVER_PREFIX " ).*" ),
519
+ *generate_implementation,
520
+ goto_model,
521
+ message_handler);
522
+ goto_model.goto_functions .update ();
523
+
524
524
reinitialize_model ();
525
525
}
526
526
0 commit comments