Repository navigation
[pulse] keep analysing the caller when a summary cannot be applied because of aliasing - #2342
Merged
Merged
Conversation
…cause of aliasing
This catches the null dereference that `AliasSpecialization.java` currently declares as a false
negative in `FN_coincidingCellsThenNullDerefBad`, added by "[pulse] keep earlier aliases when
specializing a callee again". That method is renamed here, because it is now reported.
When a call's argument aliases another of its arguments, applying the callee's summary binds one
caller address to two callee addresses. Pulse asks for an alias specialization, and when the
alias cannot be expressed as one it gave up and returned no disjuncts at all, so nothing after
the call was analysed and any defect there was lost:
static int f(int* q, int k) { q[k & 7] = 1; q[0] = 2; return k; }
void g() {
int* a = new int[8];
f(a, 0); // q[k & 7] and q[0] are the same cell
Node* p = nullptr;
p->v; // never analysed, so the null dereference was missed
}
There were two ways out of that state and they disagreed. `case_if_specialization_is_impossible`
already classifies the call as unknown, but the branch taken when no further specialization is
possible returned "known call" with an empty disjunct list instead, and the only fallback to the
unknown-call model was guarded by `--pulse-force-continue` and by the callee having no normal
post -- neither of which holds here, since the summary itself is fine and it is the application
that failed. Route the impossible case to the handler that exists for it, and fall back to the
unknown-call model whenever the summary could not be applied.
This recovers reports rather than removing them, and the imprecision of not knowing what the
call did is smaller than losing the whole of the rest of the procedure.
Worth calling out for review: the new fallback is deliberately not gated on
`--pulse-force-continue`. That option concerns a callee with no normal post, whereas here the
summary is fine and it is the application that failed, so the existing guard would not fire for
this class of call even with the option on. The consequence is that someone running
`--no-pulse-force-continue` now gets unknown-call modelling for these calls, which both test
suites below use and which is why they show a difference at all. Gating it instead on that
option, or on a new one, is a reasonable alternative if you would rather the flag keep its
broader meaning.
Limitations: the call is treated as unknown, so what the caller knew about its arguments is
forgotten; a branch on a value the callee left unchanged can become feasible. This is the same
imprecision Pulse already applies to any unknown call, now reached by more call sites. The
recovered disjuncts also consume the per-procedure disjunct budget, and a procedure that
previously had no post now has one, so the effect reaches its callers too.
## Test plan
Measured by running the new test file against this branch and against its parent, so that new
reports and controls are told apart rather than assumed.
Newly reported: `coincidingCellsThenNullDerefBad` in the existing Java alias-specialization test,
which is renamed here because it is no longer a false negative, and `coinciding_cells_bad` in
`call_aliasing_summary.cpp`. Those are the only two reports this change adds.
Controls, all of which already report on the parent and still do: `distinct_cells_bad`,
`separate_array_bad`, `shared_array_bad`, `shared_array_one_read_bad` and `no_call_bad`. The
first four are covered by alias specialization, so they pin that this change does not regress
the cases specialization already handles; the last has no call at all. `clean_call_ok`, whose
summary applies cleanly, reports nothing of its own.
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.
This catches the null dereference that
AliasSpecialization.javacurrently declares as a falsenegative in
FN_coincidingCellsThenNullDerefBad, added by "[pulse] keep earlier aliases whenspecializing a callee again". That method is renamed here, because it is now reported.
When a call's argument aliases another of its arguments, applying the callee's summary binds one
caller address to two callee addresses. Pulse asks for an alias specialization, and when the
alias cannot be expressed as one it gave up and returned no disjuncts at all, so nothing after
the call was analysed and any defect there was lost:
static int f(int* q, int k) { q[k & 7] = 1; q[0] = 2; return k; }
void g() {
int* a = new int[8];
f(a, 0); // q[k & 7] and q[0] are the same cell
Node* p = nullptr;
p->v; // never analysed, so the null dereference was missed
}
There were two ways out of that state and they disagreed.
case_if_specialization_is_impossiblealready classifies the call as unknown, but the branch taken when no further specialization is
possible returned "known call" with an empty disjunct list instead, and the only fallback to the
unknown-call model was guarded by
--pulse-force-continueand by the callee having no normalpost -- neither of which holds here, since the summary itself is fine and it is the application
that failed. Route the impossible case to the handler that exists for it, and fall back to the
unknown-call model whenever the summary could not be applied.
This recovers reports rather than removing them, and the imprecision of not knowing what the
call did is smaller than losing the whole of the rest of the procedure.
Worth calling out for review: the new fallback is deliberately not gated on
--pulse-force-continue. That option concerns a callee with no normal post, whereas here thesummary is fine and it is the application that failed, so the existing guard would not fire for
this class of call even with the option on. The consequence is that someone running
--no-pulse-force-continuenow gets unknown-call modelling for these calls, which both testsuites below use and which is why they show a difference at all. Gating it instead on that
option, or on a new one, is a reasonable alternative if you would rather the flag keep its
broader meaning.
Limitations: the call is treated as unknown, so what the caller knew about its arguments is
forgotten; a branch on a value the callee left unchanged can become feasible. This is the same
imprecision Pulse already applies to any unknown call, now reached by more call sites. The
recovered disjuncts also consume the per-procedure disjunct budget, and a procedure that
previously had no post now has one, so the effect reaches its callers too.
Test plan
Measured by running the new test file against this branch and against its parent, so that new
reports and controls are told apart rather than assumed.
Newly reported:
coincidingCellsThenNullDerefBadin the existing Java alias-specialization test,which is renamed here because it is no longer a false negative, and
coinciding_cells_badincall_aliasing_summary.cpp. Those are the only two reports this change adds.Controls, all of which already report on the parent and still do:
distinct_cells_bad,separate_array_bad,shared_array_bad,shared_array_one_read_badandno_call_bad. Thefirst four are covered by alias specialization, so they pin that this change does not regress
the cases specialization already handles; the last has no call at all.
clean_call_ok, whosesummary applies cleanly, reports nothing of its own.