cmd/guru: whicherrs: don't crash on dead code
Change-Id: I5e80613ec27a4edb45516ff1ff3a88d5f9cb3a67 Reviewed-on: https://go-review.googlesource.com/21130 Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
824b504fc7
commit
47218d24f2
|
@ -21,6 +21,11 @@ func genErr(i int) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func unreachable() {
|
||||||
|
err := errVar // @whicherrs func-dead "err"
|
||||||
|
_ = err
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := genErr(0) // @whicherrs localerrs "err"
|
err := genErr(0) // @whicherrs localerrs "err"
|
||||||
_ = err
|
_ = err
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
-------- @whicherrs func-dead --------
|
||||||
|
|
||||||
|
Error: pointer analysis did not find expression (dead code?)
|
||||||
-------- @whicherrs localerrs --------
|
-------- @whicherrs localerrs --------
|
||||||
this error may point to these globals:
|
this error may point to these globals:
|
||||||
errVar
|
errVar
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"golang.org/x/tools/cmd/guru/serial"
|
"golang.org/x/tools/cmd/guru/serial"
|
||||||
"golang.org/x/tools/go/ast/astutil"
|
"golang.org/x/tools/go/ast/astutil"
|
||||||
"golang.org/x/tools/go/loader"
|
"golang.org/x/tools/go/loader"
|
||||||
|
"golang.org/x/tools/go/pointer"
|
||||||
"golang.org/x/tools/go/ssa"
|
"golang.org/x/tools/go/ssa"
|
||||||
"golang.org/x/tools/go/ssa/ssautil"
|
"golang.org/x/tools/go/ssa/ssautil"
|
||||||
)
|
)
|
||||||
|
@ -141,6 +142,9 @@ func whicherrs(q *Query) error {
|
||||||
|
|
||||||
ptares := ptrAnalysis(ptaConfig)
|
ptares := ptrAnalysis(ptaConfig)
|
||||||
valueptr := ptares.Queries[value]
|
valueptr := ptares.Queries[value]
|
||||||
|
if valueptr == (pointer.Pointer{}) {
|
||||||
|
return fmt.Errorf("pointer analysis did not find expression (dead code?)")
|
||||||
|
}
|
||||||
for g, v := range globals {
|
for g, v := range globals {
|
||||||
ptr, ok := ptares.Queries[v]
|
ptr, ok := ptares.Queries[v]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Loading…
Reference in New Issue