Skip to content

DFCC: only summarize the functions the inlined copy may call - #9561

Draft
tautschnig wants to merge 2 commits into
diffblue:developfrom
tautschnig:post-merge-fixups-9392-roots
Draft

tautschnig wants to merge 2 commits into
diffblue:developfrom
tautschnig:post-merge-fixups-9392-roots

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

Depends-on: #9560

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 write_summary_bodiest once 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-contracts took 5.5 s
instead 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

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.97129% with 67 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.27%. Comparing base (11135d7) to head (2d974d8).
⚠️ Report is 48 commits behind head on develop.

Files with missing lines Patch % Lines
.../contracts/dynamic-frames/dfcc_write_summaries.cpp 77.36% 67 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kroening kroening added the Code Contracts Function and loop contracts label Nov 28, 2026
tautschnig and others added 2 commits December 5, 2026 19:24
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
tautschnig force-pushed the post-merge-fixups-9392-roots branch from 2d974d8 to ddede44 Compare December 5, 2026 20:14

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Code Contracts Function and loop contracts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants