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 B struct { |
14 | p int |
15 | } |
16 | |
17 | func (b B) Foo() {} |
18 | |
19 | func Baz(i, j *I, b, c bool) { |
20 | if b { |
21 | i = j |
22 | } |
23 | *i = B{9} |
24 | if c { |
25 | (*i).Foo() |
26 | } else { |
27 | (*j).Foo() |
28 | } |
29 | } |
30 | |
31 | // Relevant SSA: |
32 | // func Baz(i *I, j *I, b bool, c bool): |
33 | // if b goto 1 else 2 |
34 | // 1: |
35 | // jump 2 |
36 | // 2: |
37 | // t0 = phi [0: i, 1: j] #i |
38 | // t1 = local B (complit) |
39 | // t2 = &t1.p [#0] |
40 | // *t2 = 9:int |
41 | // t3 = *t1 |
42 | // t4 = make I <- B (t3) |
43 | // *t0 = t4 |
44 | // if c goto 3 else 5 |
45 | // 3: |
46 | // t5 = *t0 |
47 | // t6 = invoke t5.Foo() |
48 | // jump 4 |
49 | // 4: |
50 | // return |
51 | // 5: |
52 | // t7 = *j |
53 | // t8 = invoke t7.Foo() |
54 | // jump 4 |
55 | |
56 | // Flow chain showing that B reaches (*i).foo(): |
57 | // t3 (B) -> t4 -> t0 -> t5 |
58 | // Flow chain showing that B reaches (*j).foo(): |
59 | // t3 (B) -> t4 -> t0 <--> j -> t7 |
60 | |
61 | // WANT: |
62 | // Local(t0) -> Local(i), Local(j), Local(t5) |
63 | // Local(i) -> Local(t0) |
64 | // Local(j) -> Local(t0), Local(t7) |
65 | // Local(t3) -> Local(t4) |
66 | // Local(t4) -> Local(t0) |
67 |
Members