| 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 | // Tests graph creation for store/load and make instructions. |
| 10 | // Note that ssa package does not have a load instruction per |
| 11 | // se. Yet, one is encoded as a unary instruction with the |
| 12 | // * operator. |
| 13 | |
| 14 | type A struct{} |
| 15 | |
| 16 | type I interface{ foo() } |
| 17 | |
| 18 | func (a A) foo() {} |
| 19 | |
| 20 | func main() { |
| 21 | a := A{} |
| 22 | var i I |
| 23 | i = a |
| 24 | ii := &i |
| 25 | (*ii).foo() |
| 26 | } |
| 27 | |
| 28 | // Relevant SSA: |
| 29 | // t0 = local A (a) |
| 30 | // t1 = new I (i) |
| 31 | // t2 = *t0 no interesting flow: concrete types |
| 32 | // t3 = make I <- A (t2) t2 -> t3 |
| 33 | // *t1 = t3 t3 -> t1 |
| 34 | // t4 = *t1 t1 -> t4 |
| 35 | // t5 = invoke t4.foo() |
| 36 | // return |
| 37 | |
| 38 | // WANT: |
| 39 | // Local(t2) -> Local(t3) |
| 40 | // Local(t3) -> Local(t1) |
| 41 | // Local(t1) -> Local(t4) |
| 42 |