[DRAFT] [pulse] forget pure unknown calls when the memory they read is written - #2202
Draft
VladimirMakaev wants to merge 2 commits into
Draft
VladimirMakaev wants to merge 2 commits into
VladimirMakaev wants to merge 2 commits into
Conversation
Pulse records `ret = f(args)` for unknown calls that havoc none of their arguments, such as const
methods. The equality survived writes to that memory, so repeated calls had to agree and loops
could not exit:
```cpp
struct Queue {
bool empty() const;
void pop();
};
int drain_bad(Queue& q) {
if (q.empty()) return 0;
while (!q.empty()) q.pop();
int* p = nullptr;
return *p; // Infer missed: null dereference
}
```
In C-family languages, forget these equalities when a store, an unknown call or a callee writes
memory reachable from their arguments; the heap is only walked when such equalities exist. Results
computed on the entry state become `f@pre(args)`, which callers equate with their own `f` calls.
## Test plan
New `_bad`, `_ok` and `_latent` tests in c/pulse/nullptr.c and cpp/pulse/unknown_functions.cpp:
calls repeated after writes, drain loops, callees that query then write, and correlation
controls. All codetoanalyze tests pass.
Substitute existing canonical definitions under a work budget and retain exact integer-range intersections. Preserve conditions, finite ranges and divisibility; skip transformations that need new equations or increase counted formula size. Add caller-level regressions, known global/field-write limitations, and a reproducible benchmark suite with measured benefits and remaining costs. Native opt build, OCaml unit tests, c/pulse, cpp/pulse and cpp/pulse-11 pass. ObjC and the multi-PR integration stack remain unvalidated.
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.
Pulse records
ret = f(args)for unknown calls that havoc none of their arguments, such as const methods. The equality survived writes to that memory, so repeated calls had to agree and loops could not exit:In C-family languages, forget these equalities when a store, an unknown call or a callee writes memory reachable from their arguments. The heap is only walked when such equalities exist. Results computed on the entry state become
f@pre(args), which callers equate with their ownfcalls. Arithmetic facts about the old results remain valid.Summary compaction runs only on C-family summaries retaining an entry-state function application. It substitutes existing canonical linear definitions under explicit work and size checks, and retains the original integer-range atoms that define the tightest bounds. It preserves conditions, finite integer ranges and divisibility. Transformations requiring new equations, capped-coefficient overflow, or increased counted formula size are skipped.
Performance and limitations
This is partial compaction, not a universal summary-size bound or a guarantee of linear analysis time.
FP_regression records this behavior.FN_regressions record direct writes, callee writes and unknown mutation.The reproducible generator, complete measurements and implementation constraints are documented in the benchmark README. The remaining pathological cases are documented for review; this PR does not claim to satisfy a universal performance bound.
Validation
Passed locally:
@runtest, including caller-import checks for signed/unsigned bounds, mixed integer kinds, divisibility and actual definition elimination.c/pulse,cpp/pulse, andcpp/pulse-11, including the existing drain-loop and correlation regressions. Existing reports and traces are unchanged; expectations add the reports from the new regression files.ObjC/ObjC++ validation with the Xcode SDK and integration measurements stacked with #2158, #2176, #2178 and #2197 remain outstanding. The review's #2202-before-#2177 landing order is unchanged. This PR remains a draft.