1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:54:43 -07:00

go.tools/go/ssa: emit a recover block if the function's results are unnamed

It is easier for clients to recover from panics if the recover block
is always present. Otherwise, the client has to work around the lack
of a recover block by synthesizing a zero value return.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/87210044
This commit is contained in:
Peter Collingbourne 2014-06-13 13:08:35 -04:00 committed by Alan Donovan
parent f0ff511183
commit ce1e99a260
3 changed files with 6 additions and 14 deletions

View File

@ -1895,14 +1895,9 @@ start:
b.setCall(fn, s.Call, &v.Call)
fn.emit(&v)
// A deferred call can cause recovery from panic.
// If the panicking function has named results,
// control resumes at the Recover block to load those
// locals (which may be mutated by the deferred call)
// and return them.
if fn.namedResults != nil {
createRecoverBlock(fn)
}
// A deferred call can cause recovery from panic,
// and control resumes at the Recover block.
createRecoverBlock(fn)
case *ast.ReturnStmt:
var results []Value

View File

@ -555,9 +555,6 @@ func runFrame(fr *frame) {
}
fr.runDefers()
fr.block = fr.fn.Recover
if fr.block == nil {
fr.result = zero(fr.fn.Signature.Results())
}
}()
for {

View File

@ -273,9 +273,9 @@ type Node interface {
// To iterate over the blocks in dominance order, use DomPreorder().
//
// Recover is an optional second entry point to which control resumes
// after a recovered panic. The Recover block may contain only a load
// of the function's named return parameters followed by a return of
// the loaded values.
// after a recovered panic. The Recover block may contain only a return
// statement, preceded by a load of the function's named return
// parameters, if any.
//
// A nested function (Parent()!=nil) that refers to one or more
// lexically enclosing local variables ("free variables") has FreeVar