Drop unused functions before property instrumentation#8975
Drop unused functions before property instrumentation#8975tautschnig wants to merge 1 commit intodiffblue:developfrom
Conversation
Move remove_unused_functions() into process_goto_program(), before goto_check_c(). For an example from Collections-C, all ~370 functions in the goto model were instrumented with pointer/bounds/overflow checks, then most were dropped. Now we drop first, instrumenting only the ~20 reachable functions. This is safe because function pointers have already been resolved and partial inlining has been performed at this point. The option guard (drop-unused-functions) ensures other tools that don't set this option are unaffected. Remove the now-redundant remove_unused_functions() call from cbmc_parse_options.cpp. Impact on Collections-C: Monolithic: 93s -> 62s Paths: 92s -> 60s Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR moves remove_unused_functions() into the shared process_goto_program() pipeline so unused functions are dropped before property instrumentation, avoiding unnecessary instrumentation work on unreachable functions.
Changes:
- Run
remove_unused_functions()inprocess_goto_program()beforegoto_check_c()whendrop-unused-functionsis enabled - Remove the now-redundant
remove_unused_functions()call (and include) fromcbmc_parse_options.cpp
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/goto-programs/process_goto_program.cpp |
Drops unused functions earlier in the pipeline to reduce instrumentation workload |
src/cbmc/cbmc_parse_options.cpp |
Removes redundant unused-function removal and header include |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // instrumenting functions that will never be reached. This is safe | ||
| // because function pointers have already been resolved and partial | ||
| // inlining has been performed above. |
There was a problem hiding this comment.
The comment asserts that function pointers “have already been resolved” and “partial inlining has been performed above,” but those passes are often option-dependent in this pipeline. To avoid misleading future readers (and to keep the safety argument accurate), reword this comment to describe the actual preconditions required by remove_unused_functions() (e.g., “after any function-pointer removal / inlining passes that are enabled”) or explicitly tie the claim to the specific earlier steps that are unconditionally executed in this function.
| // instrumenting functions that will never be reached. This is safe | |
| // because function pointers have already been resolved and partial | |
| // inlining has been performed above. | |
| // instrumenting functions that will never be reached. This is done | |
| // after function-pointer removal and after any earlier cleanup / | |
| // inlining passes in this routine that are enabled. |
| if(options.get_bool_option("drop-unused-functions")) | ||
| { | ||
| log.status() << "Removing unused functions" << messaget::eom; | ||
| remove_unused_functions(goto_model, log.get_message_handler()); | ||
| } |
There was a problem hiding this comment.
This is a behavior/performance-sensitive pipeline change (dropping functions before instrumentation). It would benefit from a regression test that fails if unreachable functions are still instrumented when --drop-unused-functions is enabled (e.g., a small program with an unreachable function containing code that would be instrumented, and an assertion on reported properties/checks or on the presence/absence of instrumentation artifacts for that function).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #8975 +/- ##
========================================
Coverage 80.50% 80.50%
========================================
Files 1704 1704
Lines 188778 188778
Branches 73 73
========================================
Hits 151975 151975
Misses 36803 36803 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I am wondering how remove_unused_functions() interacts with instrumenting an error label. |
Move remove_unused_functions() into process_goto_program(), before goto_check_c(). For an example from Collections-C, all ~370 functions in the goto model were instrumented with pointer/bounds/overflow checks, then most were dropped. Now we drop first, instrumenting only the ~20 reachable functions.
This is safe because function pointers have already been resolved and partial inlining has been performed at this point. The option guard (drop-unused-functions) ensures other tools that don't set this option are unaffected.
Remove the now-redundant remove_unused_functions() call from cbmc_parse_options.cpp.
Impact on Collections-C:
Monolithic: 93s -> 62s
Paths: 92s -> 60s