Skip to content

DFCC write summaries: write members rather than whole objects - #9565

Draft
tautschnig wants to merge 5 commits into
diffblue:developfrom
tautschnig:post-merge-fixups-9392-members
Draft

tautschnig wants to merge 5 commits into
diffblue:developfrom
tautschnig:post-merge-fixups-9392-members

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

Depends-on: #9562

The summaries that #9392 introduced write whole objects: a function
that DFCC does not instrument and that writes s->a got the summary
*s = nondet, which the loop assigns inference turns into
__CPROVER_object_whole(&s), and a write of g.a became g = nondet.
Before #9392, inlining the original body gave the targets s.a and
g.a. Loops that call such a function now havoc members that it does
not write, so that proofs that succeeded before fail. Harnesses commonly
use nondet_* helpers that set one member of a struct, and all
functions whose names start with nondet are summarized.

Record the member of a global, or of the object that a pointer parameter
points to, that a write is part of, and have the summary write only that
member. This is only done for parameters that the function neither
assigns to nor takes the address of, so that they point to the same
object throughout the function. A part of a member counts as the whole
member, because the loop assigns inference does not take members of
members as targets (see get_assigns_lhs), and a write at a
non-constant index is part of its array member. Members written by a
callee are mapped onto the caller's objects when the argument is
&object or a parameter of the caller.

Also describe the summaries in the user documentation of the loop
assigns inference, and note there that their writes are not checked.

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.

tautschnig and others added 5 commits November 23, 2026 11:17
The View section sorted the entries of a view by their irep_idt keys,
whose operator< compares the indices of the strings in the string
container rather than the strings. The expected order thus depended on
the order in which the unit test binary first created the strings "i"
to "l", and the test failed once the new write-summary unit tests,
which are linked before it, created "l" first. Sort by the key names
instead.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
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 `originst`, `write_summaryt`, `write_summariest` and
`write_summary_bodiest` to dfcc_write_summaries.{h,cpp}, with the class
declarations in the header. 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 simplifications:
- `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;`.
- 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, of recursive functions, of array operations and
`havoc_object`; what results may point to; and the cases in which the
summary is unknown), and that `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.

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 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>
`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 diffblue#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>
The summaries that diffblue#9392 introduced replace the bodies of functions
that DFCC does not instrument, so that a write the summary misses can
make the loop assigns inference leave out an object that the loop
changes, which may prove assertions that do not hold. Two kinds of
writes were missed.

The analysis handled the OTHER instructions `array_set`, `array_copy`,
`array_replace` and `havoc_object`, and took every other OTHER
instruction to write nothing. `array_equal`, however, assigns its third
operand (see goto_rw.cpp and symex_other.cpp), and statements such as
`cpp_delete` write to memory as well. Record the write of
`array_equal`, list the statements that write nothing (those that symex
ignores or that only read), and make the summary unknown, so that the
function keeps its body, for any other statement.

The analysis only tracks the origins of values whose type contains
pointers: the origins of `(uintptr_t)q` are empty. That is sound as
long as a value without pointers never becomes a pointer other than
through a cast, which the analysis treats as pointing anywhere. Memory
can, however, be read as a different type than it was written:

  union { int *p; uintptr_t l; } u;
  u.l = (uintptr_t)q;
  *u.p = 2;

The analysis found that `u.p` points nowhere, so the summary of this
function said it writes nothing, rather than that its writes are
unknown, and its body was replaced by an empty one. The same happens
for `*(uintptr_t *)&p = (uintptr_t)q; *p = 2;`, and for a pointer read
from an integer variable through `*(int **)&l`. Today this is masked
because the loop assigns inference also drops such writes when it
inlines the body (diffblue#9393), but the summaries are meant to be
conservative, and they should not depend on that. Treat the contents of
an object as unknown when part of it is written as another type
(through a union member, byte_extract or typecast lvalue of an object
with pointers), and the contents of the locals a pointer points to as
unknown when the pointer is cast to a pointer to another type (other
than void). Values built with union literals, byte updates, `with` on
unions, or byte_extract as another type are unknown as well.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
The summaries that diffblue#9392 introduced write whole objects: a function
that DFCC does not instrument and that writes `s->a` got the summary
`*s = nondet`, which the loop assigns inference turns into
`__CPROVER_object_whole(&s)`, and a write of `g.a` became `g = nondet`.
Before diffblue#9392, inlining the original body gave the targets `s.a` and
`g.a`. Loops that call such a function now havoc members that it does
not write, so that proofs that succeeded before fail. Harnesses commonly
use `nondet_*` helpers that set one member of a struct, and all
functions whose names start with `nondet` are summarized.

Record the member of a global, or of the object that a pointer parameter
points to, that a write is part of, and have the summary write only that
member. This is only done for parameters that the function neither
assigns to nor takes the address of, so that they point to the same
object throughout the function. A part of a member counts as the whole
member, because the loop assigns inference does not take members of
members as targets (see `get_assigns_lhs`), and a write at a
non-constant index is part of its array member. Members written by a
callee are mapped onto the caller's objects when the argument is
`&object` or a parameter of the caller.

Also describe the summaries in the user documentation of the loop
assigns inference, and note there that their writes are not checked.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.70588% with 70 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.29%. Comparing base (11135d7) to head (4f17f38).
⚠️ Report is 4 commits behind head on develop.

Files with missing lines Patch % Lines
.../contracts/dynamic-frames/dfcc_write_summaries.cpp 84.23% 70 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9565      +/-   ##
===========================================
+ Coverage    81.28%   81.29%   +0.01%     
===========================================
  Files         1725     1728       +3     
  Lines       191618   192001     +383     
  Branches        73       73              
===========================================
+ Hits        155751   156091     +340     
- Misses       35867    35910      +43     

☔ 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.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant