Skip to content

x/tools/gopls/internal/analysis/unusedfunc: spurious reports in packages that use build tags (or assembly) #71686

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

Open
adonovan opened this issue Feb 12, 2025 · 2 comments
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) BugReport Issues describing a possible bug in the Go implementation. gopls/analysis Issues related to running analysis in gopls gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Feb 12, 2025

gopls' unusedfunc analysis may report spurious "function f is unused" diagnostics when uses exist but only in build-tagged files of the same package that are ignored in the current configuration. See my incorrect delayed comment on https://go.dev/cl/630415 for an example of the confusion.

@cherrymui suggested that the analyzer should offer to move the declaration into the tagged, ignored file that needs it, but that presupposes that our analysis is aware of the ignored file, which it isn't, and which is in general a challenging problem.

But still we could do better than the status quo: if the package contains ignored files, we could qualify the diagnostic with some reference to the build tag. It could be generic such as "(may depend on build tags)", or specific such as "(assuming !purego tags)", where the latter computes a falsifying tag assignment. (If we go the latter route, the analysis framework should provide helpers to do the heavy lifting.)

In principle this should be done for any analyzer whose correctness depends on the package as a whole, not just the current file.

Related: in runtime, this analyzer reports a number of false positives on unreferenced intrinsics--functions that, though never referenced from Go source in the runtime, are referenced indirectly from compiler-generated object code--and on functions that are referenced only from assembly code. The unusedfuncs analyzer should suppress diagnostics for intrinsics, and parse (all?) assembly files in the package looking for references.

@adonovan adonovan added Analysis Issues related to static analysis (vet, x/tools/go/analysis) gopls/analysis Issues related to running analysis in gopls labels Feb 12, 2025
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Feb 12, 2025
@gopherbot gopherbot added this to the Unreleased milestone Feb 12, 2025
@gabyhelp
Copy link

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 12, 2025
@jba jba modified the milestones: Unreleased, gopls/backlog Feb 13, 2025
@adonovan adonovan changed the title x/tools/gopls/internal/analysis/unusedfunc: spurious reports in packages that use build tags x/tools/gopls/internal/analysis/unusedfunc: spurious reports in packages that use build tags (or assembly) Feb 13, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/649256 mentions this issue: gopls/internal/analysis/unusedfunc: don't report runtime intrinsics

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) BugReport Issues describing a possible bug in the Go implementation. gopls/analysis Issues related to running analysis in gopls gopls Issues related to the Go language server, gopls. 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