github.com/powerman/golang-tools@v0.1.11-0.20220410185822-5ad214d8d803/go/callgraph/vta/testdata/src/callgraph_nested_ptr.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  type B struct{}
    18  
    19  func (b B) Foo() {}
    20  
    21  func Do(i **I) {
    22  	**i = A{}
    23  }
    24  
    25  func Bar(i **I) {
    26  	**i = B{}
    27  }
    28  
    29  func Baz(i **I) {
    30  	Do(i)
    31  	(**i).Foo()
    32  }
    33  
    34  // Relevant SSA:
    35  //  func Baz(i **I):
    36  //   t0 = Do(i)
    37  //   t1 = *i
    38  //   t2 = *t1
    39  //   t3 = invoke t2.Foo()
    40  //   return
    41  
    42  //  func Bar(i **I):
    43  //   t0 = *i
    44  //   t1 = local B (complit)
    45  //   t2 = *t1
    46  //   t3 = make I <- B (t2)
    47  //   *t0 = t3
    48  //   return
    49  
    50  // func Do(i **I):
    51  //   t0 = *i
    52  //   t1 = local A (complit)
    53  //   t2 = *t1
    54  //   t3 = make I <- A (t2)
    55  //   *t0 = t3
    56  //   return
    57  
    58  // WANT:
    59  // Baz: Do(i) -> Do; invoke t2.Foo() -> A.Foo, B.Foo