You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
go/ssa: exploit "noreturn" info to prune spurious CFG edges
This CL causes the buildssa analyzer to exploit interprocedural
"noreturn" information (computed by the ctrlflow analyzer)
when building SSA. This allows it to prune infeasible control-flow
edges after a call that cannot return, such as t.Fatal or log.Fatal,
making the dominator tree deeper and improving the precision of
downstream analysis such as nilness and yield.
For example, nilness can now report cases such as this:
f, err := os.Open("")
if err != nil {
log.Fatal(err) // can't return
}
if err != nil { // "impossible condition"
log.Fatal(err)
}
f.Close()
and it now reports 26 (was 20) diagnostics in std.
Similarly, gopls' yield analyzer is now silent where
before it reported a false positive here:
return func(yield func(int) bool) {
for {
if !yield(55) { // "yield may be called again after returning false"
runtime.Goexit()
}
}
}
Various "internal" hooks were required to expose the three
hidden accessor functions, which are logically equivalent
to these potential future API additions:
(cfg.CFG).NoReturn() bool
(*ctrlflow.CFGs).NoReturn(*types.Func) bool
(*ssa.Program).SetNoReturn(func (*types.Func) bool)
See golang/go#76161 for the proposal.
Change-Id: Ic91572a19f062babd520762dfe6d5749e12d8cd0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/716920
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Markus Kusano <kusano@google.com>
0 commit comments