Debian Codegraph @

go/callgraph/vta/testdata/src/panic.go

raw symbols SCIP
1 // Copyright 2021 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // go:build ignore
6
7 package testdata
8
9 type I interface {
10 foo()
11 }
12
13 type A struct{}
14
15 func (a A) foo() {}
16
17 func recover1() {
18 print("only this recover should execute")
19 if r, ok := recover().(I); ok {
20 r.foo()
21 }
22 }
23
24 func recover2() {
25 recover()
26 }
27
28 func Baz(a A) {
29 defer recover1()
30 defer recover()
31 panic(a)
32 }
33
34 // Relevant SSA:
35 // func recover1():
36 // t0 = print("only this recover...":string)
37 // t1 = recover()
38 // t2 = typeassert,ok t1.(I)
39 // t3 = extract t2 #0
40 // t4 = extract t2 #1
41 // if t4 goto 1 else 2
42 // 1:
43 // t5 = invoke t3.foo()
44 // jump 2
45 // 2:
46 // return
47 //
48 // func recover2():
49 // t0 = recover()
50 // return
51 //
52 // func Baz(i I):
53 // defer recover1()
54 // t0 = make interface{} <- A (a)
55 // panic t2
56
57 // t0 argument to panic in Baz gets ultimately connected to recover
58 // registers t1 in recover1() and t0 in recover2().
59
60 // WANT:
61 // Panic -> Recover
62 // Local(t0) -> Panic
63 // Recover -> Local(t0), Local(t1)