Skip to content

[liveness] do not report objects kept for the side effects of their constructor - #2314

Open
VladimirMakaev wants to merge 1 commit into
meta:mainfrom
VladimirMakaev:liveness-constructor-side-effects
Open

VladimirMakaev wants to merge 1 commit into
meta:mainfrom
VladimirMakaev:liveness-constructor-side-effects

Conversation

@VladimirMakaev

Copy link
Copy Markdown
Contributor

A local that is only constructed was always reported as a dead store, even when its constructor
has effects outside the object.

void register_object();
struct Registrar {
  Registrar() { register_object(); }
};
int f(int x) {
  Registrar r; // DEAD_STORE reported before, but constructing r is the point
  return x * 2;
}

Report such a local only when its constructor writes nothing but the object and its own locals,
following calls to other constructors up to three levels deep. A constructor without a body is
assumed to have side effects unless it is compiler-generated. Copies and moves, from an object of
the same class passed by reference, are still reported whatever their constructor does.

Limitations: a constructor calling a function other than a constructor is assumed to have side
effects.

Test plan

New _ok, _bad and FN_ tests in cpp/liveness/dead_stores.cpp; the existing expectations do
not change.

@meta-cla meta-cla Bot added the CLA Signed label Nov 20, 2026
…onstructor

A local that is only constructed was always reported as a dead store, even when its constructor
has effects outside the object.

    void register_object();
    struct Registrar {
      Registrar() { register_object(); }
    };
    int f(int x) {
      Registrar r; // DEAD_STORE reported before, but constructing r is the point
      return x * 2;
    }

Report such a local only when its constructor writes nothing but the object and its own locals,
following calls to other constructors up to three levels deep. A constructor without a body is
assumed to have side effects unless it is compiler-generated. Copies and moves, from an object of
the same class passed by reference, are still reported whatever their constructor does.

Limitations: a constructor calling a function other than a constructor is assumed to have side
effects.

## Test plan
New `_ok`, `_bad` and `FN_` tests in `cpp/liveness/dead_stores.cpp`; the existing expectations do
not change.
@VladimirMakaev
VladimirMakaev force-pushed the liveness-constructor-side-effects branch from ee2dafe to def33a7 Compare November 20, 2026 16:23

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant