| 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 | I |
| 15 | } |
| 16 | |
| 17 | func (a *A) Do() { |
| 18 | a.Foo() |
| 19 | } |
| 20 | |
| 21 | type B struct{} |
| 22 | |
| 23 | func (b B) Foo() {} |
| 24 | |
| 25 | func NewA(b B) *A { |
| 26 | return &A{I: &b} |
| 27 | } |
| 28 | |
| 29 | func Baz(b B) { |
| 30 | a := NewA(b) |
| 31 | a.Do() |
| 32 | } |
| 33 | |
| 34 | // Relevant SSA: |
| 35 | // func Baz(b B): |
| 36 | // t0 = local B (b) |
| 37 | // *t0 = b |
| 38 | // t1 = *t0 |
| 39 | // t2 = NewA(t1) |
| 40 | // t3 = (*A).Do(t2) |
| 41 | // return |
| 42 | // |
| 43 | // func (a *A) Do(): |
| 44 | // t0 = &a.I [#0] |
| 45 | // t1 = *t0 |
| 46 | // t2 = invoke t1.Foo() |
| 47 | // return |
| 48 | // |
| 49 | // Name: (testdata.A).Foo |
| 50 | // Synthetic: wrapper for func (testdata.I).Foo() |
| 51 | // Location: testdata/callgraph_fields.go:10:2 |
| 52 | // func (arg0 testdata.A) Foo(): |
| 53 | // t0 = local testdata.A () |
| 54 | // *t0 = arg0 |
| 55 | // t1 = &t0.I [#0] |
| 56 | // t2 = *t1 |
| 57 | // t3 = invoke t2.Foo() |
| 58 | // return |
| 59 | // |
| 60 | // Name: (*testdata.A).Foo |
| 61 | // Synthetic: wrapper for func (testdata.I).Foo() |
| 62 | // Location: testdata/callgraph_fields.go:10:2 |
| 63 | // func (arg0 *testdata.A) Foo(): |
| 64 | // t0 = &arg0.I [#0] |
| 65 | // t1 = *t0 |
| 66 | // t2 = invoke t1.Foo() |
| 67 | // return |
| 68 | // |
| 69 | // func (b B) Foo(): |
| 70 | // t0 = local B (b) |
| 71 | // *t0 = b |
| 72 | // return |
| 73 | // |
| 74 | // func (b *testdata.B) Foo(): |
| 75 | // t0 = ssa:wrapnilchk(b, "testdata.B":string, "Foo":string) |
| 76 | // t1 = *t0 |
| 77 | // t2 = (testdata.B).Foo(t1) |
| 78 | // return |
| 79 | // |
| 80 | // func NewA(b B) *A: |
| 81 | // t0 = new B (b) |
| 82 | // *t0 = b |
| 83 | // t1 = new A (complit) |
| 84 | // t2 = &t1.I [#0] |
| 85 | // t3 = make I <- *B (t0) |
| 86 | // *t2 = t3 |
| 87 | // return t1 |
| 88 | |
| 89 | // WANT: |
| 90 | // Baz: (*A).Do(t2) -> A.Do; NewA(t1) -> NewA |
| 91 | // A.Do: invoke t1.Foo() -> B.Foo |
| 92 |