| 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 J interface { |
| 10 | Foo() |
| 11 | Bar() |
| 12 | } |
| 13 | |
| 14 | type B struct { |
| 15 | p int |
| 16 | } |
| 17 | |
| 18 | func (b B) Foo() {} |
| 19 | func (b B) Bar() {} |
| 20 | |
| 21 | func Wobble(b *B, s []J) { |
| 22 | x := (*[3]J)(s) |
| 23 | x[1] = b |
| 24 | |
| 25 | a := &s[2] |
| 26 | (*a).Bar() |
| 27 | } |
| 28 | |
| 29 | // Relevant SSA: |
| 30 | // func Wobble(b *B, s []J): |
| 31 | // t0 = slice to array pointer *[3]J <- []J (s) *[3]J |
| 32 | // t1 = &t0[1:int] *J |
| 33 | // t2 = make J <- *B (b) J |
| 34 | // *t1 = t2 |
| 35 | // t3 = &s[2:int] *J |
| 36 | // ... |
| 37 | |
| 38 | // WANT: |
| 39 | // Local(t1) -> Slice([]testdata.J) |
| 40 | // Slice([]testdata.J) -> Local(t1), Local(t3) |
| 41 |