3838#include < ansi-c/goto-conversion/link_to_library.h>
3939#include < goto-instrument/contracts/cfg_info.h>
4040#include < goto-instrument/contracts/utils.h>
41+ #include < goto-instrument/generate_function_bodies.h>
4142#include < goto-instrument/nondet_static.h>
4243#include < langapi/language.h>
4344#include < langapi/language_file.h>
@@ -492,21 +493,6 @@ void dfcct::transform_goto_model()
492493
493494 library.inhibit_front_end_builtins ();
494495
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.
510496 goto_model.goto_functions .update ();
511497
512498 remove_skip (goto_model);
@@ -516,11 +502,25 @@ void dfcct::transform_goto_model()
516502
517503 // This can prune too many functions if function pointers have not been
518504 // 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.
521507 remove_unused_functions (goto_model, message_handler);
522508 goto_model.goto_functions .update ();
523509
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+
524524 reinitialize_model ();
525525}
526526
0 commit comments