aboutsummaryrefslogtreecommitdiff
path: root/go/callgraph/vta/testdata/src/panic.go
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2022-03-29 00:50:59 -0700
committerDan Willemsen <dwillemsen@google.com>2022-03-29 00:52:27 -0700
commitf10932f763d058b0dcb3acfb795c869996fef47b (patch)
tree7e04d345c214f3efac3c4b86c7ec3e831c500437 /go/callgraph/vta/testdata/src/panic.go
parentd6d1ab63f7e2d16fb9a1f1d29755d12da90aa0bb (diff)
parente693fb417253d14786976bd29a456961aa8b6343 (diff)
downloadgolang-x-tools-f10932f763d058b0dcb3acfb795c869996fef47b.tar.gz
Merge commit 'e693fb417253d14786976bd29a456961aa8b6343'
Change-Id: I65e50880732e718fa2264e47ef7cc19e37cc2f05
Diffstat (limited to 'go/callgraph/vta/testdata/src/panic.go')
-rw-r--r--go/callgraph/vta/testdata/src/panic.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/go/callgraph/vta/testdata/src/panic.go b/go/callgraph/vta/testdata/src/panic.go
new file mode 100644
index 000000000..2d39c70ea
--- /dev/null
+++ b/go/callgraph/vta/testdata/src/panic.go
@@ -0,0 +1,66 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// go:build ignore
+
+package testdata
+
+type I interface {
+ foo()
+}
+
+type A struct{}
+
+func (a A) foo() {}
+
+func recover1() {
+ print("only this recover should execute")
+ if r, ok := recover().(I); ok {
+ r.foo()
+ }
+}
+
+func recover2() {
+ recover()
+}
+
+func Baz(a A) {
+ defer recover1()
+ panic(a)
+}
+
+// Relevant SSA:
+// func recover1():
+// 0:
+// t0 = print("only this recover...":string)
+// t1 = recover()
+// t2 = typeassert,ok t1.(I)
+// t3 = extract t2 #0
+// t4 = extract t2 #1
+// if t4 goto 1 else 2
+// 1:
+// t5 = invoke t3.foo()
+// jump 2
+// 2:
+// return
+//
+// func recover2():
+// t0 = recover()
+// return
+//
+// func Baz(i I):
+// t0 = local A (a)
+// *t0 = a
+// defer recover1()
+// t1 = *t0
+// t2 = make interface{} <- A (t1)
+// panic t2
+
+// t2 argument to panic in Baz gets ultimately connected to recover
+// registers t1 in recover1() and t0 in recover2().
+
+// WANT:
+// Panic -> Recover
+// Local(t2) -> Panic
+// Recover -> Local(t0), Local(t1)