]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet/all: work around vet printf checker deficiencies
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 14 Feb 2017 00:11:13 +0000 (16:11 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 21 Feb 2017 18:41:38 +0000 (18:41 +0000)
cmd/vet has a known deficiency in its handling of fmt.Formatters.
This causes a spurious printf error only for non-host platforms.
Since cmd/vet/all may get run on any given platform,
whitelists cannot help here.

Work around the issue by skipping printf tests entirely
for non-host platforms.

Work around the one known acceptable false positive from vet
by whitelisting the file that contains it.

Change-Id: Id74b3d4db0519cf9a670a065683715f856266e45
Reviewed-on: https://go-review.googlesource.com/36936
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/vet/all/main.go
src/cmd/vet/all/whitelist/all.txt

index f4ee8fe15ae374061b2c9002e4d302f035b662ac..e4c09469712e31e8b342973dfe2d0edb3387bfba 100644 (file)
@@ -59,11 +59,12 @@ func main() {
        case *flagAll:
                vetPlatforms(allPlatforms())
        default:
-               host := platform{os: build.Default.GOOS, arch: build.Default.GOARCH}
-               host.vet(runtime.GOMAXPROCS(-1))
+               hostPlatform.vet(runtime.GOMAXPROCS(-1))
        }
 }
 
+var hostPlatform = platform{os: build.Default.GOOS, arch: build.Default.GOARCH}
+
 func allPlatforms() []platform {
        var pp []platform
        cmd := exec.Command(cmdGoPath, "tool", "dist", "list")
@@ -177,6 +178,14 @@ var ignorePathPrefixes = [...]string{
        "cmd/go/testdata/",
        "cmd/vet/testdata/",
        "go/printer/testdata/",
+       // fmt_test contains a known bad format string.
+       // We cannot add it to any given whitelist,
+       // because it won't show up for any non-host platform,
+       // due to deficiencies in vet.
+       // Just whitelist the whole file.
+       // TODO: If vet ever uses go/loader and starts working off source,
+       // this problem will likely go away.
+       "fmt/fmt_test.go",
 }
 
 func vetPlatforms(pp []platform) {
@@ -224,7 +233,18 @@ func (p platform) vet(ncpus int) {
        // and no clear way to improve vet to eliminate large chunks of them.
        // And having them in the whitelists will just cause annoyance
        // and churn when working on the runtime.
-       cmd = exec.Command(cmdGoPath, "tool", "vet", "-unsafeptr=false", ".")
+       args := []string{"tool", "vet", "-unsafeptr=false"}
+       if p != hostPlatform {
+               // When not checking the host platform, vet gets confused by
+               // the fmt.Formatters in cmd/compile,
+               // so just skip the printf checks on non-host platforms for now.
+               // There's not too much platform-specific code anyway.
+               // TODO: If vet ever uses go/loader and starts working off source,
+               // this problem will likely go away.
+               args = append(args, "-printf=false")
+       }
+       args = append(args, ".")
+       cmd = exec.Command(cmdGoPath, args...)
        cmd.Dir = filepath.Join(runtime.GOROOT(), "src")
        cmd.Env = env
        stderr, err := cmd.StderrPipe()
index 7250de1999ed395521e1acd3c948a6c5df12ab01..1d118b0d58a48241c399a84b8f850113be7e78c2 100644 (file)
@@ -23,7 +23,6 @@ runtime/sys_GOOS_ARCHSUFF.s: [GOARCH] cannot check cross-package assembly functi
 // Legitimate vet complaints in which we are testing for correct runtime behavior
 // in bad situations that vet can also detect statically.
 cmd/cover/testdata/test.go: unreachable code
-fmt/fmt_test.go: arg nil for printf verb %s of wrong type: untyped nil
 encoding/json/decode_test.go: struct field m has json tag but is not exported
 encoding/json/decode_test.go: struct field m2 has json tag but is not exported
 encoding/json/tagkey_test.go: struct field tag `:"BadFormat"` not compatible with reflect.StructTag.Get: bad syntax for struct tag key