Skip to content
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

x/tools/go/analysis/passes/nilness: check pointers inside structs as well #43301

Open
ainar-g opened this issue Dec 21, 2020 · 2 comments
Open
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@ainar-g
Copy link
Contributor

ainar-g commented Dec 21, 2020

nilness currently (as of golang/tools@ae774e9781d2 with Go 1.15.6) correctly reports this issue:

if pmax == nil {
        max = *pmax
}

But not this one:

if v.max == nil {
        max = *v.max
}

Full reproduction code.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Dec 21, 2020
@gopherbot gopherbot added this to the Unreleased milestone Dec 21, 2020
@ainar-g ainar-g changed the title x/tools/go/analysis/passes/nilness: check pointers insite structs as well x/tools/go/analysis/passes/nilness: check pointers inside structs as well Dec 21, 2020
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 21, 2020
@cagedmantis
Copy link
Contributor

/cc @matloob

@adonovan
Copy link
Member

This would require implementing the GVN (global value numbering) optimization in golang.org/x/tools/go/ssa to recognize that both occurrences of the repeated expression v.max must have the same value. This is not trivial in general: any operations in between the two statements could change the address of v, or assign to its max field.

@adonovan adonovan added the Analysis Issues related to static analysis (vet, x/tools/go/analysis) label Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants