aboutsummaryrefslogtreecommitdiff
path: root/go/callgraph/vta/testdata/src/panic.go
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-03-30 16:55:43 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-03-30 16:55:43 +0000
commit3225eca48f7ce16eb31b2dd5a170806c1214a49e (patch)
tree7e04d345c214f3efac3c4b86c7ec3e831c500437 /go/callgraph/vta/testdata/src/panic.go
parent457aa020f87e3a763226dc76aa3459fd23d0aa11 (diff)
parentf10932f763d058b0dcb3acfb795c869996fef47b (diff)
downloadgolang-x-tools-3225eca48f7ce16eb31b2dd5a170806c1214a49e.tar.gz
Snap for 8383211 from f10932f763d058b0dcb3acfb795c869996fef47b to build-tools-release
Change-Id: I0969e0c20848f202469acc85c3681437b8b62fdc
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)