3 // Copyright 2015 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test escape analysis for maps.
14 m := make(map[*int]*int) // ERROR "make\(map\[\*int\]\*int\) does not escape"
15 // BAD: i should not escape
16 i := 0 // ERROR "moved to heap: i"
17 // BAD: j should not escape
18 j := 0 // ERROR "moved to heap: j"
24 m := make(map[*int]*int) // ERROR "make\(map\[\*int\]\*int\) does not escape"
25 // BAD: i should not escape
26 i := 0 // ERROR "moved to heap: i"
27 j := 0 // ERROR "moved to heap: j"
32 func map2() map[*int]*int {
33 m := make(map[*int]*int) // ERROR "make\(map\[\*int\]\*int\) escapes to heap"
34 i := 0 // ERROR "moved to heap: i"
35 j := 0 // ERROR "moved to heap: j"
41 m := make(map[*int]*int) // ERROR "make\(map\[\*int\]\*int\) does not escape"
42 i := 0 // ERROR "moved to heap: i"
43 // BAD: j should not escape
44 j := 0 // ERROR "moved to heap: j"
54 m := make(map[*int]*int) // ERROR "make\(map\[\*int\]\*int\) does not escape"
55 // BAD: i should not escape
56 i := 0 // ERROR "moved to heap: i"
57 j := 0 // ERROR "moved to heap: j"
61 // We want to test exactly "for k, v := range m" rather than "for _, v := range m".
62 // The following if is merely to use (but not leak) k.
70 func map5(m map[*int]*int) { // ERROR "m does not escape"
71 i := 0 // ERROR "moved to heap: i"
72 j := 0 // ERROR "moved to heap: j"
76 func map6(m map[*int]*int) { // ERROR "m does not escape"
78 m = make(map[*int]*int) // ERROR "make\(map\[\*int\]\*int\) does not escape"
80 i := 0 // ERROR "moved to heap: i"
81 j := 0 // ERROR "moved to heap: j"
86 // BAD: i should not escape
87 i := 0 // ERROR "moved to heap: i"
88 // BAD: j should not escape
89 j := 0 // ERROR "moved to heap: j"
90 m := map[*int]*int{&i: &j} // ERROR "map\[\*int\]\*int{...} does not escape"
95 i := 0 // ERROR "moved to heap: i"
96 j := 0 // ERROR "moved to heap: j"
97 m := map[*int]*int{&i: &j} // ERROR "map\[\*int\]\*int{...} escapes to heap"
102 // BAD: i should not escape
103 i := 0 // ERROR "moved to heap: i"
104 j := 0 // ERROR "moved to heap: j"
105 m := map[*int]*int{&i: &j} // ERROR "map\[\*int\]\*int{...} does not escape"