Skip to content

Add live variable analysis and dead store check - #459

Merged
jgardn3r merged 13 commits into
masterfrom
lva
Sep 11, 2026
Merged

jgardn3r merged 13 commits into
masterfrom
lva

Conversation

@jgardn3r

@jgardn3r jgardn3r commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

This PR implements #455.

There are two main parts to this PR. Other than the Check, nothing is slated to be added to the public API; everything remains internal.

1. Live variable analysis

The BlockDataFlowVisitor inspects a single Block, notifying its call site of usages and assignments to variables.

LocalDataFlowProperties represent what variables are assigned or used before assignment for a block. This is a fundamental building block for live variable analysis.

LiveVariables contain the information about which variables are alive coming in and going out of a given block. Additionally, there is some other information about the entire graph that comes in handy when implementing the dead store check.

To support these changes, a LiveVariable interface was added to abstract across name declarations and references.

2. Dead store check

This is the first check that uses variable liveness to add issues. High-level, this check raises issues on assignments of variables that aren't subsequently used, either by going out of scope or being reassigned.

Other changes

Some other changes were made in service of improving the modelling of control flow graphs.

@jgardn3r
jgardn3r requested a review from cirras September 3, 2026 03:32
@jgardn3r jgardn3r linked an issue Sep 3, 2026 that may be closed by this pull request
3 tasks

@cirras cirras left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some feedback items to address, but this is looking great. Looking forward to getting this new rule into the analysis.

Comment thread delphi-frontend/src/main/java/au/com/integradev/delphi/cfg/lva/LiveVariable.java Outdated
Comment thread CHANGELOG.md Outdated
@jgardn3r

jgardn3r commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

Oops, I didn't mean to commit the test that failed CI.

Raise statements have an optional `at expression` which should be
accessible through the API.
Comment thread delphi-checks/src/main/java/au/com/integradev/delphi/checks/DeadStoreCheck.java Outdated
Comment thread delphi-checks/src/main/java/au/com/integradev/delphi/checks/DeadStoreCheck.java Outdated
Comment thread delphi-checks/src/main/java/au/com/integradev/delphi/checks/DeadStoreCheck.java Outdated
Comment thread delphi-checks/src/main/java/au/com/integradev/delphi/checks/DeadStoreCheck.java Outdated
A control flow graph is tied more closely to a statement list, rather
than a routine implementation. That is because all statement lists can
have a control flow graph, particularly `initialization` and
`finalization` sections.
This provides the node the control flow graph was constructed from.
This will allow consumers to reason about the surrounding context,
e.g., subroutines, when using a `ControlFlowGraph`.

@cirras cirras left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ready to go. Nice work!

@jgardn3r
jgardn3r merged commit bf8ca12 into master Sep 11, 2026
4 checks passed
@jgardn3r
jgardn3r deleted the lva branch September 11, 2026 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New rule: Dead stores should be removed

2 participants