Skip to content

Commit b2df0bd

Browse files
committed
cmd/vet/all: use x/tools/go/analysis/cmd/vet not cmd/vet
cmd/vet/all applies vet to all packages in the standard tree. It is run for every configuration using this command: GO_BUILDER_NAME=misc-vetall go tool dist test by the misc-vetall builder (see chart at build.golang.org). Ideally we would switch to 'go vet', but it effectively does a partial build. This means that its analysis has accurate type information, so it reports slightly fewer spurious diagnostics. However, it is more than twice as slow. Instead, cmd/vet/all builds and runs golang.org/x/tools/go/analysis/cmd/vet, which uses x/tools/go/packages to load the entire std lib from source. It takes about 4min to run all OS/ARCH pairs. An important consequence is that golang.org/x/tools must be on your $GOPATH to run cmd/vet/all. The test has been temporarily modified to warn and skip if this is not the case. This is a preparatory step for switching to the new cmd/vet based on vet-lite. Whitelist changes: - The two "deadcode" diagnostics removed from the whitelist were due to if-conditions that could now be proven false. - The asmdecl warnings are now printed with the log.Printf prefix, so they are discarded by the parser and needn't be whitelisted. Change-Id: I6486508b0de2cd947c897523af086a408cbaf4a8 Reviewed-on: https://go-review.googlesource.com/c/149097 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent a18638c commit b2df0bd

15 files changed

+81
-50
lines changed

src/cmd/vet/all/main.go

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// The vet/all command runs go vet on the standard library and commands.
88
// It compares the output against a set of whitelists
99
// maintained in the whitelist directory.
10+
//
11+
// This program attempts to build packages from golang.org/x/tools,
12+
// which must be in your GOPATH.
1013
package main
1114

1215
import (
@@ -18,6 +21,7 @@ import (
1821
"go/types"
1922
"internal/testenv"
2023
"io"
24+
"io/ioutil"
2125
"log"
2226
"os"
2327
"os/exec"
@@ -217,13 +221,40 @@ func (p platform) vet() {
217221
w := make(whitelist)
218222
w.load(p.os, p.arch)
219223

220-
// 'go tool vet .' is considerably faster than 'go vet ./...'
224+
tmpdir, err := ioutil.TempDir("", "cmd-vet-all")
225+
if err != nil {
226+
log.Fatal(err)
227+
}
228+
defer os.RemoveAll(tmpdir)
229+
230+
// Build the go/packages-based vet command from the x/tools
231+
// repo. It is considerably faster than "go vet", which rebuilds
232+
// the standard library.
233+
vetTool := filepath.Join(tmpdir, "vet")
234+
cmd := exec.Command(cmdGoPath, "build", "-o", vetTool, "golang.org/x/tools/go/analysis/cmd/vet")
235+
cmd.Dir = filepath.Join(runtime.GOROOT(), "src")
236+
cmd.Stderr = os.Stderr
237+
cmd.Stdout = os.Stderr
238+
if err := cmd.Run(); err != nil {
239+
if _, err := build.Default.Import("golang.org/x/tools/go/analysis/cmd/vet", "", 0); err != nil {
240+
fmt.Printf("skipping because golang.org/x/tools is not in GOPATH")
241+
return
242+
}
243+
log.Fatal(err)
244+
}
245+
221246
// TODO: The unsafeptr checks are disabled for now,
222247
// because there are so many false positives,
223248
// and no clear way to improve vet to eliminate large chunks of them.
224249
// And having them in the whitelists will just cause annoyance
225250
// and churn when working on the runtime.
226-
cmd := exec.Command(cmdGoPath, "tool", "vet", "-unsafeptr=false", "-source", ".")
251+
cmd = exec.Command(vetTool,
252+
"-unsafeptr=0",
253+
"-nilness=0", // expensive, uses SSA
254+
"std",
255+
"cmd/...",
256+
"cmd/compile/internal/gc/testdata",
257+
)
227258
cmd.Dir = filepath.Join(runtime.GOROOT(), "src")
228259
cmd.Env = append(os.Environ(), "GOOS="+p.os, "GOARCH="+p.arch, "CGO_ENABLED=0")
229260
stderr, err := cmd.StderrPipe()
@@ -243,6 +274,9 @@ NextLine:
243274
if strings.HasPrefix(line, "vet: ") {
244275
// Typecheck failure: Malformed syntax or multiple packages or the like.
245276
// This will yield nicer error messages elsewhere, so ignore them here.
277+
278+
// This includes warnings from asmdecl of the form:
279+
// "vet: foo.s:16: [amd64] cannot check cross-package assembly function"
246280
continue
247281
}
248282

@@ -254,22 +288,48 @@ NextLine:
254288
io.Copy(os.Stderr, stderr)
255289
break
256290
}
291+
if strings.HasPrefix(line, "# ") {
292+
// 'go vet' prefixes the output of each vet invocation by a comment:
293+
// # [package]
294+
continue
295+
}
257296

258-
fields := strings.SplitN(line, ":", 3)
297+
// Parse line.
298+
// Assume the part before the first ": "
299+
// is the "file:line:col: " information.
300+
// TODO(adonovan): parse vet -json output.
259301
var file, lineno, msg string
260-
switch len(fields) {
261-
case 2:
262-
// vet message with no line number
263-
file, msg = fields[0], fields[1]
264-
case 3:
265-
file, lineno, msg = fields[0], fields[1], fields[2]
266-
default:
302+
if i := strings.Index(line, ": "); i >= 0 {
303+
msg = line[i+len(": "):]
304+
305+
words := strings.Split(line[:i], ":")
306+
switch len(words) {
307+
case 3:
308+
_ = words[2] // ignore column
309+
fallthrough
310+
case 2:
311+
lineno = words[1]
312+
fallthrough
313+
case 1:
314+
file = words[0]
315+
316+
// Make the file name relative to GOROOT/src.
317+
if rel, err := filepath.Rel(cmd.Dir, file); err == nil {
318+
file = rel
319+
}
320+
default:
321+
// error: too many columns
322+
}
323+
}
324+
if file == "" {
267325
if !parseFailed {
268326
parseFailed = true
269327
fmt.Fprintf(os.Stderr, "failed to parse %s vet output:\n", p)
270328
}
271329
fmt.Fprintln(os.Stderr, line)
330+
continue
272331
}
332+
273333
msg = strings.TrimSpace(msg)
274334

275335
for _, ignore := range ignorePathPrefixes {

src/cmd/vet/all/whitelist/386.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// 386-specific vet whitelist. See readme.txt for details.
22

3-
internal/bytealg/compare_386.s: [386] cannot check cross-package assembly function: cmpstring is in package runtime
4-
53
// startup code uses non-standard calling convention and intentionally
64
// omits args.
75
runtime/asm_386.s: [386] rt0_go: use of 4(SP) points beyond argument frame

src/cmd/vet/all/whitelist/all.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ go/types/scope.go: method WriteTo(w io.Writer, n int, recurse bool) should have
99

1010
// False positives.
1111

12-
// Nothing much to do about cross-package assembly. Unfortunate.
13-
internal/bytealg/equal_ARCHSUFF.s: [GOARCH] cannot check cross-package assembly function: memequal is in package runtime
14-
internal/bytealg/equal_ARCHSUFF.s: [GOARCH] cannot check cross-package assembly function: memequal_varlen is in package runtime
15-
1612
// The write barrier is called directly by the compiler, so no Go def
1713
runtime/asm_ARCHSUFF.s: [GOARCH] gcWriteBarrier: function gcWriteBarrier missing Go declaration
1814

@@ -22,8 +18,6 @@ encoding/json/decode_test.go: struct field m has json tag but is not exported
2218
encoding/json/decode_test.go: struct field m2 has json tag but is not exported
2319
encoding/json/decode_test.go: struct field s has json tag but is not exported
2420
encoding/json/tagkey_test.go: struct field tag `:"BadFormat"` not compatible with reflect.StructTag.Get: bad syntax for struct tag key
25-
runtime/testdata/testprog/deadlock.go: unreachable code
26-
runtime/testdata/testprog/deadlock.go: unreachable code
2721

2822
// Compiler tests that make sure even vet-failing code adheres to the spec.
2923
cmd/compile/internal/gc/testdata/arithConst_test.go: a (64 bits) too small for shift of 4294967296
@@ -68,3 +62,7 @@ cmd/link/link_test.go: struct field tag "\n\tLondon. Michaelmas term lately over
6862
cmd/link/link_test.go: struct field tag "\n\tIt was grand to see how the wind awoke, and bent the trees, and drove the rain before it like a cloud of smoke; and to hear the solemn thunder, and to see the lightning; and while thinking with awe of the tremendous powers by which our little lives are encompassed, to consider how beneficent they are, and how upon the smallest flower and leaf there was already a freshness poured from all this seeming rage, which seemed to make creation new again." not compatible with reflect.StructTag.Get: bad syntax for struct tag key
6963
cmd/link/link_test.go: struct field tag "\n\tJarndyce and Jarndyce drones on. This scarecrow of a suit has, over the course of time, become so complicated, that no man alive knows what it means. The parties to it understand it least; but it has been observed that no two Chancery lawyers can talk about it for five minutes, without coming to a total disagreement as to all the premises. Innumerable children have been born into the cause; innumerable young people have married into it; innumerable old people have died out of it. Scores of persons have deliriously found themselves made parties in Jarndyce and Jarndyce, without knowing how or why; whole families have inherited legendary hatreds with the suit. The little plaintiff or defendant, who was promised a new rocking-horse when Jarndyce and Jarndyce should be settled, has grown up, possessed himself of a real horse, and trotted away into the other world. Fair wards of court have faded into mothers and grandmothers; a long procession of Chancellors has come in and gone out; the legion of bills in the suit have been transformed into mere bills of mortality; there are not three Jarndyces left upon the earth perhaps, since old Tom Jarndyce in despair blew his brains out at a coffee-house in Chancery Lane; but Jarndyce and Jarndyce still drags its dreary length before the Court, perennially hopeless." not compatible with reflect.StructTag.Get: bad syntax for struct tag key
7064
cmd/link/link_test.go: struct field tag "\n\tThe one great principle of the English law is, to make business for itself. There is no other principle distinctly, certainly, and consistently maintained through all its narrow turnings. Viewed by this light it becomes a coherent scheme, and not the monstrous maze the laity are apt to think it. Let them but once clearly perceive that its grand principle is to make business for itself at their expense, and surely they will cease to grumble." not compatible with reflect.StructTag.Get: bad syntax for struct tag key
65+
66+
// Tests of Decode(nil) trigger legitimate diagnostics.
67+
encoding/gob/encoder_test.go: call of Decode passes non-pointer
68+
encoding/gob/encoder_test.go: call of Decode passes non-pointer

src/cmd/vet/all/whitelist/amd64.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
// False positives.
44

5-
// Nothing much to do about cross-package assembly. Unfortunate.
6-
internal/bytealg/compare_amd64.s: [amd64] cannot check cross-package assembly function: cmpstring is in package runtime
7-
85
// reflect trampolines intentionally omit arg size. Same for morestack.
96
runtime/asm_amd64.s: [amd64] morestack: use of 8(SP) points beyond argument frame
107
runtime/asm_amd64.s: [amd64] morestack: use of 16(SP) points beyond argument frame

src/cmd/vet/all/whitelist/arm.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// arm-specific vet whitelist. See readme.txt for details.
22

3-
internal/bytealg/compare_arm.s: [arm] cannot check cross-package assembly function: cmpstring is in package runtime
4-
53
// Intentionally missing declarations.
64
runtime/asm_arm.s: [arm] emptyfunc: function emptyfunc missing Go declaration
75
runtime/asm_arm.s: [arm] armPublicationBarrier: function armPublicationBarrier missing Go declaration

src/cmd/vet/all/whitelist/arm64.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// arm64-specific vet whitelist. See readme.txt for details.
22

3-
internal/bytealg/compare_arm64.s: [arm64] cannot check cross-package assembly function: cmpstring is in package runtime
4-
53
// Intentionally missing declarations.
64
runtime/asm_arm64.s: [arm64] addmoduledata: function addmoduledata missing Go declaration
75
runtime/duff_arm64.s: [arm64] duffzero: function duffzero missing Go declaration

src/cmd/vet/all/whitelist/mipsx.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// mips/mipsle-specific vet whitelist. See readme.txt for details.
22

3-
internal/bytealg/compare_mipsx.s: [GOARCH] cannot check cross-package assembly function: cmpstring is in package runtime
4-
53
runtime/tls_mipsx.s: [GOARCH] save_g: function save_g missing Go declaration
64
runtime/tls_mipsx.s: [GOARCH] load_g: function load_g missing Go declaration
75
runtime/sys_linux_mipsx.s: [GOARCH] clone: 12(R29) should be mp+8(FP)

src/cmd/vet/all/whitelist/nacl_386.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// nacl/386-specific vet whitelist. See readme.txt for details.
22

3-
runtime/sys_nacl_386.s: [386] cannot check cross-package assembly function: naclWrite is in package syscall
4-
runtime/sys_nacl_386.s: [386] cannot check cross-package assembly function: now is in package syscall
53
runtime/sys_nacl_386.s: [386] nacl_clock_gettime: function nacl_clock_gettime missing Go declaration
64
runtime/sys_nacl_386.s: [386] setldt: function setldt missing Go declaration
75
runtime/sys_nacl_386.s: [386] sigtramp: use of 20(SP) points beyond argument frame

src/cmd/vet/all/whitelist/nacl_amd64p32.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// nacl/amd64p32-specific vet whitelist. See readme.txt for details.
22

3-
internal/bytealg/compare_amd64p32.s: [amd64p32] cannot check cross-package assembly function: cmpstring is in package runtime
4-
53
// reflect trampolines intentionally omit arg size. Same for morestack.
64
runtime/asm_amd64p32.s: [amd64p32] morestack: use of 8(SP) points beyond argument frame
75
runtime/asm_amd64p32.s: [amd64p32] morestack: use of 16(SP) points beyond argument frame
@@ -13,8 +11,6 @@ runtime/sys_nacl_amd64p32.s: [amd64p32] sigtramp: unknown variable ctxt
1311
runtime/sys_nacl_amd64p32.s: [amd64p32] sigtramp: unknown variable ctxt
1412
runtime/sys_nacl_amd64p32.s: [amd64p32] sigtramp: unknown variable ctxt
1513
runtime/sys_nacl_amd64p32.s: [amd64p32] nacl_sysinfo: function nacl_sysinfo missing Go declaration
16-
runtime/sys_nacl_amd64p32.s: [amd64p32] cannot check cross-package assembly function: naclWrite is in package syscall
17-
runtime/sys_nacl_amd64p32.s: [amd64p32] cannot check cross-package assembly function: now is in package syscall
1814
runtime/sys_nacl_amd64p32.s: [amd64p32] nacl_clock_gettime: function nacl_clock_gettime missing Go declaration
1915
runtime/sys_nacl_amd64p32.s: [amd64p32] settls: function settls missing Go declaration
2016

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// nacl/arm-specific vet whitelist. See readme.txt for details.
22

33
runtime/asm_arm.s: [arm] sigreturn: function sigreturn missing Go declaration
4-
runtime/sys_nacl_arm.s: [arm] cannot check cross-package assembly function: naclWrite is in package syscall
5-
runtime/sys_nacl_arm.s: [arm] cannot check cross-package assembly function: now is in package syscall
64
runtime/sys_nacl_arm.s: [arm] nacl_clock_gettime: function nacl_clock_gettime missing Go declaration
75
runtime/sys_nacl_arm.s: [arm] nacl_sysinfo: function nacl_sysinfo missing Go declaration
86
runtime/sys_nacl_arm.s: [arm] read_tls_fallback: function read_tls_fallback missing Go declaration

src/cmd/vet/all/whitelist/ppc64x.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// ppc64-specific vet whitelist. See readme.txt for details.
22

3-
internal/bytealg/compare_ppc64x.s: [GOARCH] cannot check cross-package assembly function: cmpstring is in package runtime
4-
53
runtime/asm_ppc64x.s: [GOARCH] reginit: function reginit missing Go declaration
64
runtime/asm_ppc64x.s: [GOARCH] goexit: use of 24(R1) points beyond argument frame
75
runtime/asm_ppc64x.s: [GOARCH] addmoduledata: function addmoduledata missing Go declaration

src/cmd/vet/all/whitelist/s390x.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
internal/bytealg/compare_s390x.s: [s390x] cannot check cross-package assembly function: cmpstring is in package runtime
21
runtime/asm_s390x.s: [s390x] addmoduledata: function addmoduledata missing Go declaration
32
runtime/memclr_s390x.s: [s390x] memclr_s390x_exrl_xc: function memclr_s390x_exrl_xc missing Go declaration
43
runtime/memmove_s390x.s: [s390x] memmove_s390x_exrl_mvc: function memmove_s390x_exrl_mvc missing Go declaration
54
runtime/tls_s390x.s: [s390x] save_g: function save_g missing Go declaration
65
runtime/tls_s390x.s: [s390x] load_g: function load_g missing Go declaration
7-
internal/cpu/cpu_s390x.s: [s390x] stfle: invalid MOVD of ret+0(FP); cpu.facilityList is 32-byte value
8-
internal/cpu/cpu_s390x.s: [s390x] kmQuery: invalid MOVD of ret+0(FP); cpu.queryResult is 16-byte value
9-
internal/cpu/cpu_s390x.s: [s390x] kmcQuery: invalid MOVD of ret+0(FP); cpu.queryResult is 16-byte value
10-
internal/cpu/cpu_s390x.s: [s390x] kmctrQuery: invalid MOVD of ret+0(FP); cpu.queryResult is 16-byte value
11-
internal/cpu/cpu_s390x.s: [s390x] kmaQuery: invalid MOVD of ret+0(FP); cpu.queryResult is 16-byte value
12-
internal/cpu/cpu_s390x.s: [s390x] kimdQuery: invalid MOVD of ret+0(FP); cpu.queryResult is 16-byte value
13-
internal/cpu/cpu_s390x.s: [s390x] klmdQuery: invalid MOVD of ret+0(FP); cpu.queryResult is 16-byte value
6+
internal/cpu/cpu_s390x.s: [s390x] stfle: invalid MOVD of ret+0(FP); internal/cpu.facilityList is 32-byte value
7+
internal/cpu/cpu_s390x.s: [s390x] kmQuery: invalid MOVD of ret+0(FP); internal/cpu.queryResult is 16-byte value
8+
internal/cpu/cpu_s390x.s: [s390x] kmcQuery: invalid MOVD of ret+0(FP); internal/cpu.queryResult is 16-byte value
9+
internal/cpu/cpu_s390x.s: [s390x] kmctrQuery: invalid MOVD of ret+0(FP); internal/cpu.queryResult is 16-byte value
10+
internal/cpu/cpu_s390x.s: [s390x] kmaQuery: invalid MOVD of ret+0(FP); internal/cpu.queryResult is 16-byte value
11+
internal/cpu/cpu_s390x.s: [s390x] kimdQuery: invalid MOVD of ret+0(FP); internal/cpu.queryResult is 16-byte value
12+
internal/cpu/cpu_s390x.s: [s390x] klmdQuery: invalid MOVD of ret+0(FP); internal/cpu.queryResult is 16-byte value

src/cmd/vet/all/whitelist/wasm.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
// False positives.
44

5-
// Nothing much to do about cross-package assembly. Unfortunate.
6-
internal/bytealg/compare_wasm.s: [wasm] cannot check cross-package assembly function: cmpstring is in package runtime
7-
85
// morestack intentionally omits arg size.
96
runtime/asm_wasm.s: [wasm] morestack: use of 8(SP) points beyond argument frame
107
runtime/asm_wasm.s: [wasm] morestack: use of 16(SP) points beyond argument frame

src/cmd/vet/all/whitelist/windows_386.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ runtime/sys_windows_386.s: [386] setldt: function setldt missing Go declaration
66
runtime/sys_windows_386.s: [386] callbackasm1+0: function callbackasm1+0 missing Go declaration
77
runtime/sys_windows_386.s: [386] tstart: function tstart missing Go declaration
88
runtime/sys_windows_386.s: [386] tstart_stdcall: RET without writing to 4-byte ret+4(FP)
9-
runtime/sys_windows_386.s: [386] cannot check cross-package assembly function: now is in package time

src/cmd/vet/all/whitelist/windows_amd64.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ runtime/sys_windows_amd64.s: [amd64] ctrlhandler: RET without writing to 4-byte
55
runtime/sys_windows_amd64.s: [amd64] callbackasm1: function callbackasm1 missing Go declaration
66
runtime/sys_windows_amd64.s: [amd64] tstart_stdcall: RET without writing to 4-byte ret+8(FP)
77
runtime/sys_windows_amd64.s: [amd64] settls: function settls missing Go declaration
8-
runtime/sys_windows_amd64.s: [amd64] cannot check cross-package assembly function: now is in package time

0 commit comments

Comments
 (0)