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

cmd/vet,x/tools/go/analysis/passes/printf: broken with GODEBUG=gotypesalias=1 #68796

Closed
findleyr opened this issue Aug 8, 2024 · 13 comments
Closed
Assignees
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@findleyr
Copy link
Contributor

findleyr commented Aug 8, 2024

Repro, originating from @adonovan's investigation of #68744:

> cat bad.go
package main

import "fmt"

func main() {
        fmt.Printf("%s", 123)
        wrapf("%s", 123)
}

func wrapf(format string, args ...any) {
        fmt.Printf(format, args...)
}
> go version
go version go1.23rc2 linux/amd64
> go vet bad.go 
# command-line-arguments
# [command-line-arguments]
./bad.go:6:2: fmt.Printf format %s has arg 123 of wrong type int
./bad.go:7:2: command-line-arguments.wrapf format %s has arg 123 of wrong type int
> GODEBUG=gotypesalias=0 go vet bad.go 
# command-line-arguments
# [command-line-arguments]
./bad.go:6:2: fmt.Printf format %s has arg 123 of wrong type int
./bad.go:7:2: command-line-arguments.wrapf format %s has arg 123 of wrong type int
> GODEBUG=gotypesalias=1 go vet bad.go 
# command-line-arguments
# [command-line-arguments]
./bad.go:6:2: fmt.Printf format %s has arg 123 of wrong type int

When GODEBUG=gotypesalias=1 (the default in 1.23), the printf analyzer fails to report a diagnostic for the wrapf printf wrapper, due to a missing call to types.Unalias.

Separately, it appears the default vet tool distributed with 1.23rc2 (or built on the release branch with make.bash) does not have GODEBUG=gotypesalias=1. Otherwise, this should have been caught by the vet integration tests. I will file a separate issue for that.

It may be the case that the two bugs mentioned in the previous two paragraphs effectively cancel themselves out for the Go distribution. However, I think we should at least block the release until we understand both better.

@findleyr findleyr added this to the Go1.23 milestone Aug 8, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/603938 mentions this issue: go/analysis/passes/printf: add missing Unalias call

@adonovan adonovan changed the title cmd/vet,x/tools/go/analysis/passes/printf: broken with GOTYPESALIAS=1 cmd/vet,x/tools/go/analysis/passes/printf: broken with GODEBUG=gotypesalias=1 Aug 8, 2024
gopherbot pushed a commit to golang/tools that referenced this issue Aug 8, 2024
The maybePrintfWrapper function checks to see that a function
has the form of a printf wrapper, but it wrongly assumed that
the representation of the type of the "args ...any" parameter
is exactly interface{}, not a named alias. This will not work
with gotypesalias=1.

Unfortunately our CL system failed to report this (or indeed
any gotypesalias=1 coverage at all) because of a bug in the
Go bootstrapping process that, in the absence of a go.work file
(which sets the language version to go1.23), the default values
of the GODEBUG table were based on an older version of Go.
(The problem was only noticed when running a test of unitchecker
locally in the context of issue 68796.)

Also, the problem wasn't caught by our existing tests of the
printf checker because they all pre-date "any", and so spelled
it "interface{}".

This CL will need to be vendored into the go1.23 release.

Updates golang/go#68744
Updates golang/go#68796

Change-Id: I834ea20c2a684ffcd7ce9494d3700371ae6ab3c1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/603938
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
@findleyr
Copy link
Contributor Author

findleyr commented Aug 8, 2024

Now that we understand it better, I don't think this needs to block the release. A missing vet diagnostic for printf wrappers (that use any, not interface{}) seems to be benign enough to fix in 1.23.1.

@findleyr findleyr modified the milestones: Go1.23, Go1.23.1 Aug 8, 2024
@dmitshur
Copy link
Contributor

dmitshur commented Aug 8, 2024

Thanks. For this to be fixed in go1.23.1, it'll still need to be fixed at tip first and then backported, so moving this to Go1.24 milestone and re-adding release-blocker. Please use the usual process (https://go.dev/wiki/MinorReleases) to create a separate backport tracking issue in the Go1.23.1 milestone.

@dmitshur dmitshur modified the milestones: Go1.23.1, Go1.24 Aug 8, 2024
@dmitshur dmitshur added release-blocker NeedsFix The path to resolution is known, but the work has not been done. labels Aug 8, 2024
@findleyr
Copy link
Contributor Author

findleyr commented Aug 9, 2024

@gopherbot please backport this issue to 1.23. It is a regression that may affect vet if #68797 is also backported.

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #68813 (for 1.23).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@findleyr
Copy link
Contributor Author

findleyr commented Aug 9, 2024

To clarify: right now the version of vet distributed with go1.23rc2 DOES work as expected. It is only if we fix the incorrect GODEBUG value to have gotypesalias=1 that we would observe the printf bug, and even if that happened I don't think the nature of this bug is severe enough to block this release. I'm not even sure we should backport the fix to 1.23, unless we decide to also backport a fix for #68797.

One of the motivations for marking this as a release blocker was that we weren't sure if GODEBUG was being set correctly during compilation of ALL programs. It turns out that the issue with GODEBUG is restricted to toolchain programs, as a result of the bootstrap process. That is a much smaller problem.

@golang golang deleted a comment from xiaokentrl Aug 11, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/609435 mentions this issue: [gopls-release-branch.0.16] go/analysis/passes/printf: add missing Unalias call

gopherbot pushed a commit to golang/tools that referenced this issue Aug 29, 2024
…alias call

The maybePrintfWrapper function checks to see that a function
has the form of a printf wrapper, but it wrongly assumed that
the representation of the type of the "args ...any" parameter
is exactly interface{}, not a named alias. This will not work
with gotypesalias=1.

Unfortunately our CL system failed to report this (or indeed
any gotypesalias=1 coverage at all) because of a bug in the
Go bootstrapping process that, in the absence of a go.work file
(which sets the language version to go1.23), the default values
of the GODEBUG table were based on an older version of Go.
(The problem was only noticed when running a test of unitchecker
locally in the context of issue 68796.)

Also, the problem wasn't caught by our existing tests of the
printf checker because they all pre-date "any", and so spelled
it "interface{}".

This CL will need to be vendored into the go1.23 release.

Updates golang/go#68744
Updates golang/go#68796

Change-Id: I834ea20c2a684ffcd7ce9494d3700371ae6ab3c1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/603938
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
(cherry picked from commit 28ba991)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/609435
TryBot-Bypass: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
@dmitshur
Copy link
Contributor

dmitshur commented Sep 4, 2024

Checking on this issue as it's a release blocker for 1.24. Any updates? Thanks.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/610736 mentions this issue: vendor/golang.org/x/tools: update to v0.24.1-0.20240904143311-70f56264139c

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/610737 mentions this issue: vet: add regression test for printf checker regression

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/610739 mentions this issue: all: fix printf(var) mistakes detected by latest printf checker

@dmitshur dmitshur added the FixPending Issues that have a fix which has not yet been reviewed or submitted. label Sep 4, 2024
gopherbot pushed a commit that referenced this issue Sep 4, 2024
These will cause build failures once we vendor x/tools.

In once case I renamed a function err to errf to indicate
that it is printf-like.

Updates #68796

Change-Id: I04d57b34ee5362f530554b7e8b817f70a9088d12
Reviewed-on: https://go-review.googlesource.com/c/go/+/610739
Commit-Queue: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/610797 mentions this issue: all: fix printf(var) mistakes detected by latest printf checker

gopherbot pushed a commit to golang/crypto that referenced this issue Sep 4, 2024
These were problematic but previously easy to miss. They're now
easy to spot thanks to build failures at Go tip as of CL 610736.

For golang/go#68796.

Change-Id: I167f2cce2376b4070460389c673d973e4521d3dc
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/610797
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
Status: Done
Development

No branches or pull requests

5 participants