Skip to content

[MERGED] Further improvements for detection of unused assignments #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 23 commits into from

Conversation

Daniel-Cortez
Copy link
Contributor

What this PR does / why we need it:

This PR continues the work regarding detection of unused assignments (warnings 204 and 240), the first part of which was done in #480.

  • Fixes a bug with assignments inside loops being mistakenly reported as unused after using break or continue.
new var = 0;
for (/* ... */) {
    if (/* ... */) {
        var = 0;
        break;
    }

    // Before the fix, the compiler falsely reported the previous assignment "var = 0"
    // as unused ("warning 240: previously assigned value is never used (symbol "var")").
    var = var + 1;
}
  • Improves the unused assignment detection algorithm by tracking the "compound statement" nesting level for each assignment, which allows to detect more complicated cases of unused assignments.

Which issue(s) this PR fixes:

Fixes #479

What kind of pull this is:

  • A Bug Fix
  • A New Feature
  • Some repository meta (documentation, etc)
  • Other

Additional Documentation:

This PR relies on the fix from #532, so you'll probably want to review and merge that PR first.

This fixes `continue` and `break` not calling destructors properly in some situations.
…ED' flag when error messages are being silenced
…ctsymbols()`

This fixes the problem with the same assignments being reported repeatedly if the function has multiple `return` statements.
…`while` and `for` statements

Now unused previous assignments (warning 240) are detected by their "compound statement" nesting level.
…for" loops

We already temporarily increase `pc_nestlevel` before the whole loop (to store the assignments on a separate compound level), so we don't need to do it again.
…se" branch

Previously we had to clear all assignments in the "true" branch if the "false" one was present, so the compiler won't report assignments in the "true" branch as unused if the "false" branch also contains assignments to the same variables.
…return` and `exit`

This fixes a bug with assignments being falsely reported as unused after `return` or `exit`.
Example:
```
ReturnValue(&arg)
{
    if (/* ... */)
    {
        arg = 1;
        return;
    }
    arg = 2; // previous assignment "arg = 1" was falsely reported as unused on this line
}
```
… `memoizeassignments()` and `restoreassignments()`
@Daniel-Cortez
Copy link
Contributor Author

Daniel-Cortez commented Jul 3, 2020

Fixed a bug with false positive warnings 204 and 240 printed with random (garbage) line numbers, e.g.:

pawno\include\functions.inc(758132272) : warning 204: symbol is assigned a value that is never used: "playerid"

The reason of this problem was the bug with local constants which broke the code in memoizeassignments() and restoreassignments().
In order to fix this, I incorporated the fix from #543 into this PR.

@Daniel-Cortez Daniel-Cortez mentioned this pull request Aug 29, 2020
4 tasks
@Y-Less Y-Less closed this Sep 19, 2020
@Y-Less Y-Less changed the title Further improvements for detection of unused assignments [MERGED] Further improvements for detection of unused assignments Sep 20, 2020
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.

The warning 204 when assigning in "do{} while();" condition scope
2 participants