golang.org/x/tools@v0.21.1-0.20240520172518-788d39e776b1/go/callgraph/vta/testdata/src/phi.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 A struct{} 10 type B struct{} 11 12 type I interface{ foo() } 13 14 func (a A) foo() {} 15 func (b B) foo() {} 16 17 func Baz(b B, c bool) { 18 var i I 19 if c { 20 i = b 21 } else { 22 a := A{} 23 i = a 24 } 25 i.foo() 26 } 27 28 // Relevant SSA: 29 // func Baz(b B, c bool): 30 // 0: 31 // if c goto 1 else 3 32 // 33 // 1: 34 // t0 = make I <- B (b) 35 // jump 2 36 // 37 // 2: 38 // t1 = phi [1: t0, 3: t3] #i 39 // t2 = invoke t1.foo() 40 // return 41 // 42 // 3: 43 // t3 = make I <- A (struct{}{}:A) 44 // jump 2 45 46 // WANT: 47 // Local(b) -> Local(t0) 48 // Local(t0) -> Local(t1) 49 // Local(t3) -> Local(t1) 50 // Constant(testdata.A) -> Local(t3)