Skip to content

Commit

Permalink
go/callgraph/vta: do not assume that recovers cannot be deferred
Browse files Browse the repository at this point in the history
Otherwise, one has a panic.

Change-Id: I850d99ad373ac877bfbc2a8c2ef0c8ac98992dff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420914
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tim King <taking@google.com>
  • Loading branch information
zpavlinovic committed Aug 3, 2022
1 parent 371fc67 commit 8b9a1fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion go/callgraph/vta/graph.go
Expand Up @@ -568,7 +568,9 @@ func (b *builder) panic(p *ssa.Panic) {
func (b *builder) call(c ssa.CallInstruction) {
// When c is r := recover() call register instruction, we add Recover -> r.
if bf, ok := c.Common().Value.(*ssa.Builtin); ok && bf.Name() == "recover" {
b.addInFlowEdge(recoverReturn{}, b.nodeFromVal(c.(*ssa.Call)))
if v, ok := c.(ssa.Value); ok {
b.addInFlowEdge(recoverReturn{}, b.nodeFromVal(v))
}
return
}

Expand Down
3 changes: 2 additions & 1 deletion go/callgraph/vta/testdata/src/panic.go
Expand Up @@ -27,12 +27,12 @@ func recover2() {

func Baz(a A) {
defer recover1()
defer recover()
panic(a)
}

// Relevant SSA:
// func recover1():
// 0:
// t0 = print("only this recover...":string)
// t1 = recover()
// t2 = typeassert,ok t1.(I)
Expand All @@ -53,6 +53,7 @@ func Baz(a A) {
// t0 = local A (a)
// *t0 = a
// defer recover1()
// defer recover()
// t1 = *t0
// t2 = make interface{} <- A (t1)
// panic t2
Expand Down

0 comments on commit 8b9a1fb

Please sign in to comment.