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 | // t0 = local A (a) |
54 | // *t0 = a |
55 | // defer recover1() |
56 | // defer recover() |
57 | // t1 = *t0 |
58 | // t2 = make interface{} <- A (t1) |
59 | // panic t2 |
60 | |
61 | // t2 argument to panic in Baz gets ultimately connected to recover |
62 | // registers t1 in recover1() and t0 in recover2(). |
63 | |
64 | // WANT: |
65 | // Panic -> Recover |
66 | // Local(t2) -> Panic |
67 | // Recover -> Local(t0), Local(t1) |
68 |