Repository navigation
DFCC: only summarize the functions the inlined copy may call - #9561
Draft
tautschnig wants to merge 2 commits into
Draft
tautschnig wants to merge 2 commits into
tautschnig wants to merge 2 commits into
Conversation
3 of 4 tasks
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #9561 +/- ##
===========================================
- Coverage 81.28% 81.27% -0.01%
===========================================
Files 1725 1728 +3
Lines 191618 191739 +121
Branches 73 73
===========================================
+ Hits 155751 155833 +82
- Misses 35867 35906 +39 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
PR diffblue#9392 added about 560 lines of write-summary analysis to an anonymous namespace in dfcc_infer_loop_assigns.cpp. There, nothing outside the loop assigns inference can reach the analysis, so it can only be tested end to end, and the merged regression test passes whether or not any body is replaced by a summary. Most branches of the analysis were not run by any test. Move the analysis to dfcc_write_summaries.{h,cpp}, with the class declarations in the header. As the types are no longer file-local, give them the `dfcc_` prefix that the other public types of the module use: `originst`, `write_summaryt`, `write_summariest` and `write_summary_bodiest` become `dfcc_originst`, `dfcc_write_summaryt`, `dfcc_write_summariest` and `dfcc_write_summary_bodiest`. The code is moved unchanged, apart from splitting the member functions into declarations and out-of-class definitions, turning the static helpers of `write_summary_bodiest` into file-local functions, and the following changes: - `write_summariest::parameter_index` was written but never read. - `write_summaryt::operator==` compared the members of `originst` one by one; `originst` now has its own `operator==`, so a member added later cannot be left out of the comparison. - `has_pointers` assumed "no pointers" for a type while visiting it, "for recursive types". That entry could never be read: a type can only refer to itself through a pointer, and the pointer case does not recurse. - In `make_body`, a parameter index out of range cannot happen, as the indices come from the function's own `parameter_identifiers`. Make it an INVARIANT instead of a silent fallback. - `else if(has_pointers(t) || unknown) { if(has_pointers(t)) return false; }` is `else if(has_pointers(t)) return false;`. - The public `dfcc_write_summariest::operator[]` is const and requires that `compute` covered the function. It used to insert a default summary, which says "writes nothing", so a misuse would have given an unsound summary instead of an error. The analysis itself still relies on default entries for the fixpoint, but uses the map directly. - The file-local `write_through`, which appends nondeterministic writes to a summary body, is now `havoc_pointees`, as the analysis has an unrelated member function of the same name. - Fix a typo in a comment ("boyd"). There is no change in behaviour. Add unit tests that check the computed summaries (writes to globals, through parameters, through locals pointing to a parameter's object, of callees, through a pointer that a callee returns, to a conditional lvalue, of recursive functions, of array operations and `havoc_object`; what results may point to; and the cases in which the summary is unknown). Further unit tests check that `dfcc_write_summary_bodiest` replaces only the bodies of functions DFCC does not instrument, keeps the bodies of functions with unknown summaries, and restores the bodies; and what the summary bodies do: they havoc the objects of the pointers in a struct passed by value, havoc an object pointed to by a `void *` as bytes, and return a nondeterministic choice among the objects the result may point to. A function keeps its body if its result may point to what a non-pointer parameter points to, or if it returns a struct that contains pointers. Each of these tests fails if the branch of the code it is about is removed. Also add a regression test that fails if the inference inlines the original body: `__CPROVER_havoc_slice` is implemented with `__CPROVER_array_replace`, which the inference does not see after inlining, whereas the summary of a function that calls it writes the whole object its parameter points to. Before PR diffblue#9392, the loop in this test was not havocked and its assertion wrongly held. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
`dfcc_write_summary_bodiest` took every function that DFCC does not instrument and that has a body as a root of the write-summary analysis. That set includes `__CPROVER__start`, from which the analysis then reached `main` and every function of the program, and the inference constructs a `dfcc_write_summary_bodiest` once for each function with loops. On a program with 300 functions that each have one loop with a loop invariant and no assigns clause, all called from `main`, `goto-instrument --dfcc main --apply-loop-contracts` took 3.0 s. Only the functions that the copy being inlined may call, directly or through the functions it calls, can be inlined into it, so take only those as roots. The walk follows the calls in instrumented and uninstrumented callees alike: an uninstrumented function that keeps its body is inlined, and so are the functions it calls. The walk and `dfcc_write_summariest::compute` now share the definition of the calls they follow, which are the calls `goto_program_inline` can inline. The same program now takes 0.32 s, and the instrumented program is the same. The unit test checks that a function the copy cannot call keeps its body, and that a function reached only through an uninstrumented function that keeps its body is summarized. Both checks fail if the corresponding part of the walk is removed. Depends-on: diffblue#9560 Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig
force-pushed
the
post-merge-fixups-9392-roots
branch
from
December 5, 2026 20:14
2d974d8 to
ddede44
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends-on: #9560
write_summary_bodiesttook every function that DFCC does notinstrument and that has a body as a root of the write-summary analysis.
That set includes
__CPROVER__start, from which the analysis thenreached
mainand every function of the program, and the inferenceconstructs a
write_summary_bodiestonce for each function with loops.On a program with 300 functions that each have one loop, all called from
main,goto-instrument --dfcc main --apply-loop-contractstook 5.5 sinstead of 2.4 s before #9392.
Only the functions that the copy being inlined may call, directly or
through the functions it calls, can be inlined into it, so take only
those as roots. The same program now takes 2.5 s.
Co-authored-by: Kiro kiro-agent@users.noreply.github.com