github.com/powerman/golang-tools@v0.1.11-0.20220410185822-5ad214d8d803/go/callgraph/vta/testdata/src/panic.go (about) 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 panic(a) 31 } 32 33 // Relevant SSA: 34 // func recover1(): 35 // 0: 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 // t1 = *t0 57 // t2 = make interface{} <- A (t1) 58 // panic t2 59 60 // t2 argument to panic in Baz gets ultimately connected to recover 61 // registers t1 in recover1() and t0 in recover2(). 62 63 // WANT: 64 // Panic -> Recover 65 // Local(t2) -> Panic 66 // Recover -> Local(t0), Local(t1)