phan / phan/phan

Fix false negatives in analysis of do/while loops

Open
#2,029 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

dead code detection difficult enhancement
Dominant language
PHP
Stars
5.6k
Forks
365
Avg merge
1h 25m
Merged PRs (30d)
6

Description

Follow up to https://github.com/phan/phan/issues/2026

I really should redesign parts of this to be a completely accurate version of a definition-use graph instead of a mostly accurate version if I want to fix every edge case for do-while.

  • Also known as a use-define chain : https://en.wikipedia.org/wiki/Use-define_chain
  • As part of this change, this should also treat break as going to a different node than continue
  • Some statements are not Nodes, will need to handle this (e.g. ;2;). Creating empty ast\Node to mark blocks in the def-use graph is one way to do that.
  • Will need to refactor this to track definitions in a more generic way. (just check if it's possible to have any definition outside of a block of code instead of the current approach of tracking the specific definitions. The current approach does not work well with loops).

It'd also help in the long run if I wrote tools to represent a tool to convert the resulting definitions and usages generated by this plugin to a graph (e.g. dot file https://www.graphviz.org/doc/info/lang.html) for internal usages

  • This graph be used when debugging with graphviz as a visualizer; unit tests can verify that the resulting graphs are accurate and avoid regressions when fixing any other issues
  • If there are 3 ast\Nodes on line 7, then label the first one L7N1, the second one L7N2, etc (Some nodes will have the same column and we don't track the column).

https://github.com/phan/phan/blob/master/src/Phan/Plugin/Internal/VariableTrackerPlugin.php
https://github.com/phan/phan/tree/master/src/Phan/Plugin/Internal/VariableTracker

examples of a false positive/negative caused by break/continue - E.g. the variable is defined before a break so it isn't used within the loop, the variable is defined before a break so it isn't used within the condition, etc.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/Phan/Plugin/Internal/VariableTrackerPlugin.php and the files under src/Phan/Plugin/Internal/VariableTracker, then review issue 2026 for the do/while context. The work involves making the definition-use graph accurate for do/while control flow, distinguishing break from continue, and handling statements that are not Nodes. Done would include regression coverage for the reported false positives and negatives; graph visualization and labeling are suggested longer-term tooling.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
devtools
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.