GoPLS Viewer

Home|gopls/go/callgraph/vta/testdata/src/phi.go
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
7package testdata
8
9type A struct{}
10type B struct{}
11
12type I interface{ foo() }
13
14func (a Afoo() {}
15func (b Bfoo() {}
16
17func Baz(b Bc 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//  t0 = local B (b)
32//  *t0 = b
33//  if c goto 1 else 3
34//
35// 1:
36//  t1 = *t0
37//  t2 = make I <- B (t1)
38//  jump 2
39//
40// 2:
41//  t3 = phi [1: t2, 3: t7] #i
42//  t4 = invoke t3.foo()
43//  return
44//
45// 3:
46//  t5 = local A (a)
47//  t6 = *t5
48//  t7 = make I <- A (t6)
49//  jump 2
50
51// WANT:
52// Local(t1) -> Local(t2)
53// Local(t2) -> Local(t3)
54// Local(t7) -> Local(t3)
55// Local(t6) -> Local(t7)
56
MembersX
Baz.BlockStmt.BlockStmt.a
Members
X