aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vet/main.go
diff options
context:
space:
mode:
authorAliaksandr Valialkin <valyala@gmail.com>2017-03-13 19:17:41 +0200
committerRob Pike <r@golang.org>2017-04-19 20:03:37 +0000
commit78510bd17c35932cd45f1433adb21aeaa0587767 (patch)
tree7d05d472328cf265f671c036faa3d40c058840ad /src/cmd/vet/main.go
parent6b0bd51c1c7f34acdc5556d88a52d9a9f3b14da5 (diff)
downloadgo-78510bd17c35932cd45f1433adb21aeaa0587767.tar.gz
go-78510bd17c35932cd45f1433adb21aeaa0587767.zip
cmd/vet: skip unreachable "if" and "case" code in shift check.
Such dead code is legitimate when dealing with arch-specific types (int, uint, uintptr). The CL removes the majority of 'too small for shift' false positives from such a code. Change-Id: I62c5635a1d3774ab2d71d3d7056f0589f214cbe5 Reviewed-on: https://go-review.googlesource.com/38065 Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/cmd/vet/main.go')
-rw-r--r--src/cmd/vet/main.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/cmd/vet/main.go b/src/cmd/vet/main.go
index 8c7b2be9c7..77376c90ed 100644
--- a/src/cmd/vet/main.go
+++ b/src/cmd/vet/main.go
@@ -194,6 +194,9 @@ type File struct {
// Registered checkers to run.
checkers map[ast.Node][]func(*File, ast.Node)
+
+ // Unreachable nodes; can be ignored in shift check.
+ dead map[ast.Node]bool
}
func main() {
@@ -330,7 +333,13 @@ func doPackage(directory string, names []string, basePkg *Package) *Package {
}
astFiles = append(astFiles, parsedFile)
}
- files = append(files, &File{fset: fs, content: data, name: name, file: parsedFile})
+ files = append(files, &File{
+ fset: fs,
+ content: data,
+ name: name,
+ file: parsedFile,
+ dead: make(map[ast.Node]bool),
+ })
}
if len(astFiles) == 0 {
return nil
@@ -472,6 +481,7 @@ func (f *File) walkFile(name string, file *ast.File) {
// Visit implements the ast.Visitor interface.
func (f *File) Visit(node ast.Node) ast.Visitor {
+ f.updateDead(node)
var key ast.Node
switch node.(type) {
case *ast.AssignStmt: