[DRAFT] [pulse] keep caller arithmetic facts when applying callee comparisons - #2176
Draft
VladimirMakaev wants to merge 1 commit into
Draft
VladimirMakaev wants to merge 1 commit into
VladimirMakaev wants to merge 1 commit into
Conversation
Applying a callee's path condition could lose arithmetic facts, so comparisons made in callees led
Pulse down infeasible paths, e.g. spurious leaks of RAII file descriptors checked with `fd < 0`.
```c
int less_than(int a, int b) { return a < b; }
void f() {
int x = random();
if (x <= 0) {
return;
}
if (less_than(x, 0)) {
return;
}
if (x == 0) {
int* p = NULL;
*p = 42; // false positive: null dereference reported here
}
}
```
The fix has three parts:
- callee intervals go on the caller's representatives, and caller intervals follow the new
equalities (needed by `not_zero_or_one_*`);
- a restricted (non-negative) variable equal to a necessarily negative term is Unsat
(`assume_in_callee_*`);
- intervals of restricted variables are intersected with [0,+∞) (`negative_*`).
Either of the first two fixes the example and `owned_fd`, where the restricted variables are
tableau slacks (`x <= 0` gives `x = 1 + w`, `w >= 0`). The last two only use the non-negativity the
tableau already assumes, adding no trust in models.
## Test plan
New tests in `c/pulse/arithmetic.c` (one `FP_` for a remaining gap), `cpp/pulse/owned_fd.cpp` and
`PulseFormulaTest.ml`; reverting any part fails some of them. The C, C++, Java, Kotlin and SIL
codetoanalyze tests and the Pulse OCaml unit tests pass.
VladimirMakaev
force-pushed
the
pulse-callee-interval-merge
branch
from
October 3, 2026 21:52
5173ec7 to
1b8259a
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.
Applying a callee's path condition could lose arithmetic facts, so comparisons made in callees led
Pulse down infeasible paths, e.g. spurious leaks of RAII file descriptors checked with
fd < 0.The fix has three parts:
equalities (needed by
not_zero_or_one_*);(
assume_in_callee_*);negative_*).Either of the first two fixes the example and
owned_fd, where the restricted variables aretableau slacks (
x <= 0givesx = 1 + w,w >= 0). The last two only use the non-negativity thetableau already assumes, adding no trust in models.
Test plan
New tests in
c/pulse/arithmetic.c(oneFP_for a remaining gap),cpp/pulse/owned_fd.cppandPulseFormulaTest.ml; reverting any part fails some of them. The C, C++, Java, Kotlin and SILcodetoanalyze tests and the Pulse OCaml unit tests pass.