| 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() string |
| 11 | } |
| 12 | |
| 13 | type B struct { |
| 14 | p string |
| 15 | } |
| 16 | |
| 17 | func (b B) Foo() string { return b.p } |
| 18 | |
| 19 | func Baz(m map[I]*I) { |
| 20 | for i, v := range m { |
| 21 | *v = B{p: i.Foo()} |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | // Relevant SSA: |
| 26 | // func Baz(m map[I]*I): |
| 27 | // 0: |
| 28 | // t0 = range m |
| 29 | // jump 1 |
| 30 | // 1: |
| 31 | // t1 = next t0 |
| 32 | // t2 = extract t1 #0 |
| 33 | // if t2 goto 2 else 3 |
| 34 | // 2: |
| 35 | // t3 = extract t1 #1 |
| 36 | // t4 = extract t1 #2 |
| 37 | // t5 = local B (complit) |
| 38 | // t6 = &t5.p [#0] |
| 39 | // t7 = invoke t3.Foo() |
| 40 | // *t6 = t7 |
| 41 | // t8 = *t5 |
| 42 | // t9 = make I <- B (t8) |
| 43 | // *t4 = t9 |
| 44 | // jump 1 |
| 45 | // 3: |
| 46 | // return |
| 47 | |
| 48 | // WANT: |
| 49 | // MapKey(testdata.I) -> Local(t1[1]) |
| 50 | // Local(t1[1]) -> Local(t3) |
| 51 | // MapValue(*testdata.I) -> Local(t1[2]) |
| 52 | // Local(t1[2]) -> Local(t4), MapValue(*testdata.I) |
| 53 | // Local(t8) -> Local(t9) |
| 54 | // Local(t9) -> Local(t4) |
| 55 | // Local(t4) -> Local(t1[2]) |
| 56 |