github.com/powerman/golang-tools@v0.1.11-0.20220410185822-5ad214d8d803/go/callgraph/vta/testdata/src/stores_arrays.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 J interface {
    14  	Foo()
    15  	Bar()
    16  }
    17  
    18  type B struct {
    19  	p int
    20  }
    21  
    22  func (b B) Foo() {}
    23  func (b B) Bar() {}
    24  
    25  func Baz(b *B, S []*I, s []J) {
    26  	var x [3]I
    27  	x[1] = b
    28  
    29  	a := &s[2]
    30  	(*a).Bar()
    31  
    32  	print([3]*I{nil, nil, nil}[2])
    33  }
    34  
    35  // Relevant SSA:
    36  // func Baz(b *B, S []*I, s []J):
    37  //   t0 = local [3]I (x)
    38  //   t1 = &t0[1:int]
    39  //   ...
    40  //   t3 = &s[2:int]
    41  //   t4 = *t3
    42  //   ...
    43  //   t6 = local [3]*I (complit)
    44  //   t7 = &t6[0:int]
    45  //         ...
    46  //   t11 = t10[2:int]
    47  //   ...
    48  
    49  // WANT:
    50  // Slice([]testdata.I) -> Local(t1)
    51  // Local(t1) -> Slice([]testdata.I)
    52  // Slice([]testdata.J) -> Local(t3)
    53  // Local(t3) -> Local(t4), Slice([]testdata.J)
    54  // Local(t11) -> Slice([]*testdata.I)
    55  // Slice([]*testdata.I) -> Local(t11), PtrInterface(testdata.I)
    56  // Constant(*testdata.I) -> PtrInterface(testdata.I)