Skip to content

[pulse] keep analysing the caller when a summary cannot be applied because of aliasing - #2342

Merged
dulmarod merged 1 commit into
meta:mainfrom
VladimirMakaev:pr/pulse-alias-summary-fn-1130
Dec 1, 2026
Merged

dulmarod merged 1 commit into
meta:mainfrom
VladimirMakaev:pr/pulse-alias-summary-fn-1130

Conversation

@VladimirMakaev

Copy link
Copy Markdown
Contributor

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.

…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.
@meta-cla meta-cla Bot added the CLA Signed label Nov 30, 2026
@dulmarod
dulmarod merged commit 03af7bc into meta:main Dec 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants