]> Cypherpunks repositories - gostls13.git/commit
cmd/vet: -lostcancel: check for discarded result of context.WithCancel
authorAlan Donovan <adonovan@google.com>
Wed, 15 Jun 2016 03:50:39 +0000 (23:50 -0400)
committerAlan Donovan <adonovan@google.com>
Tue, 21 Jun 2016 14:58:33 +0000 (14:58 +0000)
commitb65cb7f198836faf6605051b95bd60a169fa5e8b
tree1095549347d98494e3fed8117df853b82e7c972d
parentd28242724872c6ab82d53a71fc775095d1171ee7
cmd/vet: -lostcancel: check for discarded result of context.WithCancel

The cfg subpackage builds a control flow graph of ast.Nodes.
The lostcancel module checks this graph to find paths, from a call to
WithCancel to a return statement, on which the cancel variable is
not used.  (A trivial case is simply assigning the cancel result to
the blank identifier.)

In a sample of 50,000 source files, the new check found 2068 blank
assignments and 118 return-before-cancel errors.  I manually inspected
20 of the latter and didn't find a single false positive among them.

Change-Id: I84cd49445f9f8d04908b04881eb1496a96611205
Reviewed-on: https://go-review.googlesource.com/24150
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/vet/deadcode.go
src/cmd/vet/doc.go
src/cmd/vet/internal/cfg/builder.go [new file with mode: 0644]
src/cmd/vet/internal/cfg/cfg.go [new file with mode: 0644]
src/cmd/vet/internal/cfg/cfg_test.go [new file with mode: 0644]
src/cmd/vet/lostcancel.go [new file with mode: 0644]
src/cmd/vet/testdata/lostcancel.go [new file with mode: 0644]