return
}
if n.Right != nil {
- mode.Fprintf(s, "%v literal", n.Right)
+ mode.Fprintf(s, "%v{%s}", n.Right, ellipsisIf(n.List.Len() != 0))
return
}
case OSTRUCTLIT, OARRAYLIT, OSLICELIT, OMAPLIT:
if mode == FErr {
- mode.Fprintf(s, "%v literal", n.Type)
+ mode.Fprintf(s, "%v{%s}", n.Type, ellipsisIf(n.List.Len() != 0))
return
}
mode.Fprintf(s, "(%v{ %.v })", n.Type, n.List)
fmt.Fprint(s, ". ")
}
}
+
+func ellipsisIf(b bool) string {
+ if b {
+ return "..."
+ }
+ return ""
+}
var _ T0 = A0{}
// But aliases and original types cannot be used with new types based on them.
-var _ N0 = T0{} // ERROR "cannot use T0 literal \(type T0\) as type N0 in assignment|incompatible type"
-var _ N0 = A0{} // ERROR "cannot use T0 literal \(type T0\) as type N0 in assignment|incompatible type"
+var _ N0 = T0{} // ERROR "cannot use T0{} \(type T0\) as type N0 in assignment|incompatible type"
+var _ N0 = A0{} // ERROR "cannot use T0{} \(type T0\) as type N0 in assignment|incompatible type"
var _ A5 = Value{}
var _ A0 = T0{}
var _ T0 = A0{}
- var _ N0 = T0{} // ERROR "cannot use T0 literal \(type T0\) as type N0 in assignment|incompatible type"
- var _ N0 = A0{} // ERROR "cannot use T0 literal \(type T0\) as type N0 in assignment|incompatible type"
+ var _ N0 = T0{} // ERROR "cannot use T0{} \(type T0\) as type N0 in assignment|incompatible type"
+ var _ N0 = A0{} // ERROR "cannot use T0{} \(type T0\) as type N0 in assignment|incompatible type"
- var _ A5 = Value{} // ERROR "cannot use reflect\.Value literal \(type reflect.Value\) as type A5 in assignment|incompatible type"
+ var _ A5 = Value{} // ERROR "cannot use reflect\.Value{} \(type reflect.Value\) as type A5 in assignment|incompatible type"
}
// Invalid type alias declarations.
_ = sum(1.0, 2.0)
_ = sum(1.5) // ERROR "integer"
_ = sum("hello") // ERROR ".hello. .type untyped string. as type int|incompatible"
- _ = sum([]int{1}) // ERROR "\[\]int literal.*as type int|incompatible"
+ _ = sum([]int{1}) // ERROR "\[\]int{...}.*as type int|incompatible"
)
func sum3(int, int, int) int { return 0 }
}
func NewBar() *Bar {
- return &Bar{42, nil} // ERROR "&Bar literal escapes to heap$"
+ return &Bar{42, nil} // ERROR "&Bar{...} escapes to heap$"
}
func NewBarp(x *int) *Bar { // ERROR "leaking param: x$"
- return &Bar{42, x} // ERROR "&Bar literal escapes to heap$"
+ return &Bar{42, x} // ERROR "&Bar{...} escapes to heap$"
}
func NewBarp2(x *int) *Bar { // ERROR "x does not escape$"
- return &Bar{*x, nil} // ERROR "&Bar literal escapes to heap$"
+ return &Bar{*x, nil} // ERROR "&Bar{...} escapes to heap$"
}
func (b *Bar) NoLeak() int { // ERROR "b does not escape$"
}
func NewBar2() *Bar2 {
- return &Bar2{[12]int{42}, nil} // ERROR "&Bar2 literal escapes to heap$"
+ return &Bar2{[12]int{42}, nil} // ERROR "&Bar2{...} escapes to heap$"
}
func (b *Bar2) NoLeak() int { // ERROR "b does not escape$"
// issue 2145
func foo73() {
- s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape$"
+ s := []int{3, 2, 1} // ERROR "\[\]int{...} does not escape$"
for _, v := range s {
vv := v
// actually just escapes its scope
}
func foo731() {
- s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape$"
+ s := []int{3, 2, 1} // ERROR "\[\]int{...} does not escape$"
for _, v := range s {
vv := v // ERROR "moved to heap: vv$"
// actually just escapes its scope
}
func foo74() {
- s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape$"
+ s := []int{3, 2, 1} // ERROR "\[\]int{...} does not escape$"
for _, v := range s {
vv := v
// actually just escapes its scope
}
func foo74a() {
- s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape$"
+ s := []int{3, 2, 1} // ERROR "\[\]int{...} does not escape$"
for _, v := range s {
vv := v // ERROR "moved to heap: vv$"
// actually just escapes its scope
// issue 3975
func foo74b() {
var array [3]func()
- s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape$"
+ s := []int{3, 2, 1} // ERROR "\[\]int{...} does not escape$"
for i, v := range s {
vv := v
// actually just escapes its scope
func foo74c() {
var array [3]func()
- s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape$"
+ s := []int{3, 2, 1} // ERROR "\[\]int{...} does not escape$"
for i, v := range s {
vv := v // ERROR "moved to heap: vv$"
// actually just escapes its scope
}
func LimitFooer(r Fooer, n int64) Fooer { // ERROR "leaking param: r$"
- return &LimitedFooer{r, n} // ERROR "&LimitedFooer literal escapes to heap$"
+ return &LimitedFooer{r, n} // ERROR "&LimitedFooer{...} escapes to heap$"
}
func foo90(x *int) map[*int]*int { // ERROR "leaking param: x$"
- return map[*int]*int{nil: x} // ERROR "map\[\*int\]\*int literal escapes to heap$"
+ return map[*int]*int{nil: x} // ERROR "map\[\*int\]\*int{...} escapes to heap$"
}
func foo91(x *int) map[*int]*int { // ERROR "leaking param: x$"
- return map[*int]*int{x: nil} // ERROR "map\[\*int\]\*int literal escapes to heap$"
+ return map[*int]*int{x: nil} // ERROR "map\[\*int\]\*int{...} escapes to heap$"
}
func foo92(x *int) [2]*int { // ERROR "leaking param: x to result ~r1 level=0$"
}
func foo107(x *int) map[*int]*int { // ERROR "leaking param: x$"
- return map[*int]*int{x: nil} // ERROR "map\[\*int\]\*int literal escapes to heap$"
+ return map[*int]*int{x: nil} // ERROR "map\[\*int\]\*int{...} escapes to heap$"
}
func foo108(x *int) map[*int]*int { // ERROR "leaking param: x$"
- return map[*int]*int{nil: x} // ERROR "map\[\*int\]\*int literal escapes to heap$"
+ return map[*int]*int{nil: x} // ERROR "map\[\*int\]\*int{...} escapes to heap$"
}
func foo109(x *int) *int { // ERROR "leaking param: x$"
- m := map[*int]*int{x: nil} // ERROR "map\[\*int\]\*int literal does not escape$"
+ m := map[*int]*int{x: nil} // ERROR "map\[\*int\]\*int{...} does not escape$"
for k, _ := range m {
return k
}
}
func foo110(x *int) *int { // ERROR "leaking param: x$"
- m := map[*int]*int{nil: x} // ERROR "map\[\*int\]\*int literal does not escape$"
+ m := map[*int]*int{nil: x} // ERROR "map\[\*int\]\*int{...} does not escape$"
return m[nil]
}
func foo111(x *int) *int { // ERROR "leaking param: x to result ~r1 level=0"
- m := []*int{x} // ERROR "\[\]\*int literal does not escape$"
+ m := []*int{x} // ERROR "\[\]\*int{...} does not escape$"
return m[0]
}
}
func foo114(x *int) *int { // ERROR "leaking param: x to result ~r1 level=0$"
- m := &Bar{ii: x} // ERROR "&Bar literal does not escape$"
+ m := &Bar{ii: x} // ERROR "&Bar{...} does not escape$"
return m.ii
}
X string
T *T
}
- t := &T{} // ERROR "&T literal escapes to heap$"
- return U{ // ERROR "U literal escapes to heap$"
+ t := &T{} // ERROR "&T{} escapes to heap$"
+ return U{ // ERROR "U{...} escapes to heap$"
X: t.X,
T: t,
}
}
func NewV(u U) *V { // ERROR "leaking param: u$"
- return &V{u.String()} // ERROR "&V literal escapes to heap$"
+ return &V{u.String()} // ERROR "&V{...} escapes to heap$"
}
func foo152() {
func ptrlitNoescape() {
// Both literal and element do not escape.
i := 0
- x := &Lit{&i} // ERROR "&Lit literal does not escape$"
+ x := &Lit{&i} // ERROR "&Lit{...} does not escape$"
_ = x
}
func ptrlitNoEscape2() {
// Literal does not escape, but element does.
i := 0 // ERROR "moved to heap: i$"
- x := &Lit{&i} // ERROR "&Lit literal does not escape$"
+ x := &Lit{&i} // ERROR "&Lit{...} does not escape$"
sink = *x
}
func ptrlitEscape() {
// Both literal and element escape.
i := 0 // ERROR "moved to heap: i$"
- x := &Lit{&i} // ERROR "&Lit literal escapes to heap$"
+ x := &Lit{&i} // ERROR "&Lit{...} escapes to heap$"
sink = x
}
}
func slicerunetostring0() {
- r := []rune{1, 2, 3} // ERROR "\[\]rune literal does not escape$"
+ r := []rune{1, 2, 3} // ERROR "\[\]rune{...} does not escape$"
s := string(r) // ERROR "string\(r\) does not escape$"
_ = s
}
func slicerunetostring1() string {
- r := []rune{1, 2, 3} // ERROR "\[\]rune literal does not escape$"
+ r := []rune{1, 2, 3} // ERROR "\[\]rune{...} does not escape$"
return string(r) // ERROR "string\(r\) escapes to heap$"
}
func slicerunetostring2() {
- r := []rune{1, 2, 3} // ERROR "\[\]rune literal does not escape$"
+ r := []rune{1, 2, 3} // ERROR "\[\]rune{...} does not escape$"
sink = string(r) // ERROR "string\(r\) escapes to heap$"
}
}
func NewBar() *Bar {
- return &Bar{42, nil} // ERROR "&Bar literal escapes to heap$"
+ return &Bar{42, nil} // ERROR "&Bar{...} escapes to heap$"
}
func NewBarp(x *int) *Bar { // ERROR "leaking param: x$"
- return &Bar{42, x} // ERROR "&Bar literal escapes to heap$"
+ return &Bar{42, x} // ERROR "&Bar{...} escapes to heap$"
}
func NewBarp2(x *int) *Bar { // ERROR "x does not escape$"
- return &Bar{*x, nil} // ERROR "&Bar literal escapes to heap$"
+ return &Bar{*x, nil} // ERROR "&Bar{...} escapes to heap$"
}
func (b *Bar) NoLeak() int { // ERROR "b does not escape$"
}
func NewBar2() *Bar2 {
- return &Bar2{[12]int{42}, nil} // ERROR "&Bar2 literal escapes to heap$"
+ return &Bar2{[12]int{42}, nil} // ERROR "&Bar2{...} escapes to heap$"
}
func (b *Bar2) NoLeak() int { // ERROR "b does not escape$"
// issue 2145
func foo73() {
- s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape$"
+ s := []int{3, 2, 1} // ERROR "\[\]int{...} does not escape$"
for _, v := range s {
vv := v
// actually just escapes its scope
}
func foo731() {
- s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape$"
+ s := []int{3, 2, 1} // ERROR "\[\]int{...} does not escape$"
for _, v := range s {
vv := v // ERROR "moved to heap: vv$"
// actually just escapes its scope
}
func foo74() {
- s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape$"
+ s := []int{3, 2, 1} // ERROR "\[\]int{...} does not escape$"
for _, v := range s {
vv := v
// actually just escapes its scope
}
func foo74a() {
- s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape$"
+ s := []int{3, 2, 1} // ERROR "\[\]int{...} does not escape$"
for _, v := range s {
vv := v // ERROR "moved to heap: vv$"
// actually just escapes its scope
// issue 3975
func foo74b() {
var array [3]func()
- s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape$"
+ s := []int{3, 2, 1} // ERROR "\[\]int{...} does not escape$"
for i, v := range s {
vv := v
// actually just escapes its scope
func foo74c() {
var array [3]func()
- s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape$"
+ s := []int{3, 2, 1} // ERROR "\[\]int{...} does not escape$"
for i, v := range s {
vv := v // ERROR "moved to heap: vv$"
// actually just escapes its scope
}
func LimitFooer(r Fooer, n int64) Fooer { // ERROR "leaking param: r$"
- return &LimitedFooer{r, n} // ERROR "&LimitedFooer literal escapes to heap$"
+ return &LimitedFooer{r, n} // ERROR "&LimitedFooer{...} escapes to heap$"
}
func foo90(x *int) map[*int]*int { // ERROR "leaking param: x$"
- return map[*int]*int{nil: x} // ERROR "map\[\*int\]\*int literal escapes to heap$"
+ return map[*int]*int{nil: x} // ERROR "map\[\*int\]\*int{...} escapes to heap$"
}
func foo91(x *int) map[*int]*int { // ERROR "leaking param: x$"
- return map[*int]*int{x: nil} // ERROR "map\[\*int\]\*int literal escapes to heap$"
+ return map[*int]*int{x: nil} // ERROR "map\[\*int\]\*int{...} escapes to heap$"
}
func foo92(x *int) [2]*int { // ERROR "leaking param: x to result ~r1 level=0$"
}
func foo107(x *int) map[*int]*int { // ERROR "leaking param: x$"
- return map[*int]*int{x: nil} // ERROR "map\[\*int\]\*int literal escapes to heap$"
+ return map[*int]*int{x: nil} // ERROR "map\[\*int\]\*int{...} escapes to heap$"
}
func foo108(x *int) map[*int]*int { // ERROR "leaking param: x$"
- return map[*int]*int{nil: x} // ERROR "map\[\*int\]\*int literal escapes to heap$"
+ return map[*int]*int{nil: x} // ERROR "map\[\*int\]\*int{...} escapes to heap$"
}
func foo109(x *int) *int { // ERROR "leaking param: x$"
- m := map[*int]*int{x: nil} // ERROR "map\[\*int\]\*int literal does not escape$"
+ m := map[*int]*int{x: nil} // ERROR "map\[\*int\]\*int{...} does not escape$"
for k, _ := range m {
return k
}
}
func foo110(x *int) *int { // ERROR "leaking param: x$"
- m := map[*int]*int{nil: x} // ERROR "map\[\*int\]\*int literal does not escape$"
+ m := map[*int]*int{nil: x} // ERROR "map\[\*int\]\*int{...} does not escape$"
return m[nil]
}
func foo111(x *int) *int { // ERROR "leaking param: x to result ~r1 level=0"
- m := []*int{x} // ERROR "\[\]\*int literal does not escape$"
+ m := []*int{x} // ERROR "\[\]\*int{...} does not escape$"
return m[0]
}
}
func foo114(x *int) *int { // ERROR "leaking param: x to result ~r1 level=0$"
- m := &Bar{ii: x} // ERROR "&Bar literal does not escape$"
+ m := &Bar{ii: x} // ERROR "&Bar{...} does not escape$"
return m.ii
}
X string
T *T
}
- t := &T{} // ERROR "&T literal escapes to heap$"
- return U{ // ERROR "U literal escapes to heap$"
+ t := &T{} // ERROR "&T{} escapes to heap$"
+ return U{ // ERROR "U{...} escapes to heap$"
X: t.X,
T: t,
}
}
func NewV(u U) *V { // ERROR "leaking param: u$"
- return &V{u.String()} // ERROR "&V literal escapes to heap$"
+ return &V{u.String()} // ERROR "&V{...} escapes to heap$"
}
func foo152() {
func ptrlitNoescape() {
// Both literal and element do not escape.
i := 0
- x := &Lit{&i} // ERROR "&Lit literal does not escape$"
+ x := &Lit{&i} // ERROR "&Lit{...} does not escape$"
_ = x
}
func ptrlitNoEscape2() {
// Literal does not escape, but element does.
i := 0 // ERROR "moved to heap: i$"
- x := &Lit{&i} // ERROR "&Lit literal does not escape$"
+ x := &Lit{&i} // ERROR "&Lit{...} does not escape$"
sink = *x
}
func ptrlitEscape() {
// Both literal and element escape.
i := 0 // ERROR "moved to heap: i$"
- x := &Lit{&i} // ERROR "&Lit literal escapes to heap$"
+ x := &Lit{&i} // ERROR "&Lit{...} escapes to heap$"
sink = x
}
}
func slicerunetostring0() {
- r := []rune{1, 2, 3} // ERROR "\[\]rune literal does not escape$"
+ r := []rune{1, 2, 3} // ERROR "\[\]rune{...} does not escape$"
s := string(r) // ERROR "string\(r\) does not escape$"
_ = s
}
func slicerunetostring1() string {
- r := []rune{1, 2, 3} // ERROR "\[\]rune literal does not escape$"
+ r := []rune{1, 2, 3} // ERROR "\[\]rune{...} does not escape$"
return string(r) // ERROR "string\(r\) escapes to heap$"
}
func slicerunetostring2() {
- r := []rune{1, 2, 3} // ERROR "\[\]rune literal does not escape$"
+ r := []rune{1, 2, 3} // ERROR "\[\]rune{...} does not escape$"
sink = string(r) // ERROR "string\(r\) escapes to heap$"
}
f := prototype
f = func(ss []string) { got = append(got, ss) } // ERROR "leaking param: ss" "func literal does not escape"
s := "string"
- f([]string{s}) // ERROR "\[\]string literal escapes to heap"
+ f([]string{s}) // ERROR "\[\]string{...} escapes to heap"
}
func field13() {
i := 0 // ERROR "moved to heap: i$"
- x := &X{p1: &i} // ERROR "&X literal does not escape$"
+ x := &X{p1: &i} // ERROR "&X{...} does not escape$"
sink = x.p1
}
func field14() {
i := 0 // ERROR "moved to heap: i$"
// BAD: &i should not escape
- x := &X{p1: &i} // ERROR "&X literal does not escape$"
+ x := &X{p1: &i} // ERROR "&X{...} does not escape$"
sink = x.p2
}
func field15() {
i := 0 // ERROR "moved to heap: i$"
- x := &X{p1: &i} // ERROR "&X literal escapes to heap$"
+ x := &X{p1: &i} // ERROR "&X{...} escapes to heap$"
sink = x
}
_ = x
}
{
- i := 0 // ERROR "moved to heap: i"
+ i := 0 // ERROR "moved to heap: i"
v := M0{&i}
var x M = v
sink = x
_ = v1
}
{
- i := 0 // ERROR "moved to heap: i"
+ i := 0 // ERROR "moved to heap: i"
v := M0{&i}
// BAD: v does not escape to heap here
var x M = v
sink = v1
}
{
- i := 0 // ERROR "moved to heap: i"
+ i := 0 // ERROR "moved to heap: i"
v := M0{&i}
// BAD: v does not escape to heap here
var x M = v
x.M()
}
{
- i := 0 // ERROR "moved to heap: i"
+ i := 0 // ERROR "moved to heap: i"
v := M0{&i}
var x M = v
mescapes(x)
{
i := 0
v := M1{&i, 0}
- var x M = v // ERROR "v does not escape"
+ var x M = v // ERROR "v does not escape"
_ = x
}
{
- i := 0 // ERROR "moved to heap: i"
+ i := 0 // ERROR "moved to heap: i"
v := M1{&i, 0}
- var x M = v // ERROR "v escapes to heap"
+ var x M = v // ERROR "v escapes to heap"
sink = x
}
{
i := 0
v := M1{&i, 0}
- var x M = v // ERROR "v does not escape"
+ var x M = v // ERROR "v does not escape"
v1 := x.(M1)
_ = v1
}
{
- i := 0 // ERROR "moved to heap: i"
+ i := 0 // ERROR "moved to heap: i"
v := M1{&i, 0}
var x M = v // ERROR "v does not escape"
v1 := x.(M1)
sink = v1 // ERROR "v1 escapes to heap"
}
{
- i := 0 // ERROR "moved to heap: i"
+ i := 0 // ERROR "moved to heap: i"
v := M1{&i, 0}
// BAD: v does not escape to heap here
var x M = v // ERROR "v escapes to heap"
x.M()
}
{
- i := 0 // ERROR "moved to heap: i"
+ i := 0 // ERROR "moved to heap: i"
v := M1{&i, 0}
- var x M = v // ERROR "v escapes to heap"
+ var x M = v // ERROR "v escapes to heap"
mescapes(x)
}
{
i := 0
v := M1{&i, 0}
- var x M = v // ERROR "v does not escape"
+ var x M = v // ERROR "v does not escape"
mdoesnotescape(x)
}
}
func efaceEscape2() {
{
i := 0
- v := &M2{&i} // ERROR "&M2 literal does not escape"
+ v := &M2{&i} // ERROR "&M2{...} does not escape"
var x M = v
_ = x
}
{
i := 0 // ERROR "moved to heap: i"
- v := &M2{&i} // ERROR "&M2 literal escapes to heap"
+ v := &M2{&i} // ERROR "&M2{...} escapes to heap"
var x M = v
sink = x
}
{
i := 0
- v := &M2{&i} // ERROR "&M2 literal does not escape"
+ v := &M2{&i} // ERROR "&M2{...} does not escape"
var x M = v
v1 := x.(*M2)
_ = v1
}
{
i := 0 // ERROR "moved to heap: i"
- v := &M2{&i} // ERROR "&M2 literal escapes to heap"
+ v := &M2{&i} // ERROR "&M2{...} escapes to heap"
// BAD: v does not escape to heap here
var x M = v
v1 := x.(*M2)
}
{
i := 0 // ERROR "moved to heap: i"
- v := &M2{&i} // ERROR "&M2 literal does not escape"
+ v := &M2{&i} // ERROR "&M2{...} does not escape"
// BAD: v does not escape to heap here
var x M = v
v1 := x.(*M2)
}
{
i := 0 // ERROR "moved to heap: i"
- v := &M2{&i} // ERROR "&M2 literal does not escape"
+ v := &M2{&i} // ERROR "&M2{...} does not escape"
// BAD: v does not escape to heap here
var x M = v
v1, ok := x.(*M2)
}
{
i := 0 // ERROR "moved to heap: i"
- v := &M2{&i} // ERROR "&M2 literal escapes to heap"
+ v := &M2{&i} // ERROR "&M2{...} escapes to heap"
// BAD: v does not escape to heap here
var x M = v
x.M()
}
{
i := 0 // ERROR "moved to heap: i"
- v := &M2{&i} // ERROR "&M2 literal escapes to heap"
+ v := &M2{&i} // ERROR "&M2{...} escapes to heap"
var x M = v
mescapes(x)
}
{
i := 0
- v := &M2{&i} // ERROR "&M2 literal does not escape"
+ v := &M2{&i} // ERROR "&M2{...} does not escape"
var x M = v
mdoesnotescape(x)
}
func dotTypeEscape() *T2 { // #11931
var x interface{}
- x = &T1{p: new(int)} // ERROR "new\(int\) escapes to heap" "&T1 literal does not escape"
- return &T2{ // ERROR "&T2 literal escapes to heap"
+ x = &T1{p: new(int)} // ERROR "new\(int\) escapes to heap" "&T1{...} does not escape"
+ return &T2{ // ERROR "&T2{...} escapes to heap"
T1: *(x.(*T1)),
}
}
var x interface{} = i // ERROR "i does not escape"
var y interface{} = j // ERROR "j does not escape"
- sink = x.(int) // ERROR "x.\(int\) escapes to heap"
+ sink = x.(int) // ERROR "x.\(int\) escapes to heap"
sink, *(&ok) = y.(int)
}
{
func constptr0() {
i := 0 // ERROR "moved to heap: i"
- x := &ConstPtr{} // ERROR "&ConstPtr literal does not escape"
+ x := &ConstPtr{} // ERROR "&ConstPtr{} does not escape"
// BAD: i should not escape here
x.p = &i
_ = x
func constptr01() *ConstPtr {
i := 0 // ERROR "moved to heap: i"
- x := &ConstPtr{} // ERROR "&ConstPtr literal escapes to heap"
+ x := &ConstPtr{} // ERROR "&ConstPtr{} escapes to heap"
x.p = &i
return x
}
func constptr02() ConstPtr {
i := 0 // ERROR "moved to heap: i"
- x := &ConstPtr{} // ERROR "&ConstPtr literal does not escape"
+ x := &ConstPtr{} // ERROR "&ConstPtr{} does not escape"
x.p = &i
return *x
}
func constptr03() **ConstPtr {
i := 0 // ERROR "moved to heap: i"
- x := &ConstPtr{} // ERROR "&ConstPtr literal escapes to heap" "moved to heap: x"
+ x := &ConstPtr{} // ERROR "&ConstPtr{} escapes to heap" "moved to heap: x"
x.p = &i
return &x
}
func constptr1() {
i := 0 // ERROR "moved to heap: i"
- x := &ConstPtr{} // ERROR "&ConstPtr literal escapes to heap"
+ x := &ConstPtr{} // ERROR "&ConstPtr{} escapes to heap"
x.p = &i
sink = x
}
func constptr2() {
i := 0 // ERROR "moved to heap: i"
- x := &ConstPtr{} // ERROR "&ConstPtr literal does not escape"
+ x := &ConstPtr{} // ERROR "&ConstPtr{} does not escape"
x.p = &i
- sink = *x // ERROR "\*x escapes to heap"
+ sink = *x // ERROR "\*x escapes to heap"
}
func constptr4() *ConstPtr {
p := new(ConstPtr) // ERROR "new\(ConstPtr\) escapes to heap"
- *p = *&ConstPtr{} // ERROR "&ConstPtr literal does not escape"
+ *p = *&ConstPtr{} // ERROR "&ConstPtr{} does not escape"
return p
}
func constptr5() *ConstPtr {
p := new(ConstPtr) // ERROR "new\(ConstPtr\) escapes to heap"
- p1 := &ConstPtr{} // ERROR "&ConstPtr literal does not escape"
+ p1 := &ConstPtr{} // ERROR "&ConstPtr{} does not escape"
*p = *p1
return p
}
// BAD: p should not escape here
func constptr6(p *ConstPtr) { // ERROR "leaking param content: p"
- p1 := &ConstPtr{} // ERROR "&ConstPtr literal does not escape"
+ p1 := &ConstPtr{} // ERROR "&ConstPtr{} does not escape"
*p1 = *p
_ = p1
}
func constptr9() ConstPtr {
p := new(ConstPtr) // ERROR "new\(ConstPtr\) does not escape"
var p1 ConstPtr2
- i := 0 // ERROR "moved to heap: i"
+ i := 0 // ERROR "moved to heap: i"
p1.p = &i
p.c = p1
return *p
}
func constptr10() ConstPtr {
- x := &ConstPtr{} // ERROR "moved to heap: x" "&ConstPtr literal escapes to heap"
+ x := &ConstPtr{} // ERROR "moved to heap: x" "&ConstPtr{} escapes to heap"
i := 0 // ERROR "moved to heap: i"
var p *ConstPtr
- p = &ConstPtr{p: &i, x: &x} // ERROR "&ConstPtr literal does not escape"
+ p = &ConstPtr{p: &i, x: &x} // ERROR "&ConstPtr{...} does not escape"
var pp **ConstPtr
pp = &p
return **pp
func constptr11() *ConstPtr {
i := 0 // ERROR "moved to heap: i"
p := new(ConstPtr) // ERROR "new\(ConstPtr\) escapes to heap"
- p1 := &ConstPtr{} // ERROR "&ConstPtr literal does not escape"
+ p1 := &ConstPtr{} // ERROR "&ConstPtr{} does not escape"
p1.p = &i
*p = *p1
return p
}
func foo1(p *int) { // ERROR "p does not escape"
- i := 0 // ERROR "moved to heap: i"
+ i := 0 // ERROR "moved to heap: i"
y := &p
*y = &i
}
var z Z
z.f = &x
p := z.f
- i := 0 // ERROR "moved to heap: i"
+ i := 0 // ERROR "moved to heap: i"
*p = &i
}
var global *byte
func f() {
- var x byte // ERROR "moved to heap: x"
+ var x byte // ERROR "moved to heap: x"
global = &*&x
}
// BAD: i should not escape
i := 0 // ERROR "moved to heap: i"
// BAD: j should not escape
- j := 0 // ERROR "moved to heap: j"
+ j := 0 // ERROR "moved to heap: j"
m[&i] = &j
_ = m
}
func map1() *int {
m := make(map[*int]*int) // ERROR "make\(map\[\*int\]\*int\) does not escape"
// BAD: i should not escape
- i := 0 // ERROR "moved to heap: i"
- j := 0 // ERROR "moved to heap: j"
+ i := 0 // ERROR "moved to heap: i"
+ j := 0 // ERROR "moved to heap: j"
m[&i] = &j
return m[&i]
}
m := make(map[*int]*int) // ERROR "make\(map\[\*int\]\*int\) does not escape"
i := 0 // ERROR "moved to heap: i"
// BAD: j should not escape
- j := 0 // ERROR "moved to heap: j"
+ j := 0 // ERROR "moved to heap: j"
m[&i] = &j
var r []*int
for k := range m {
func map4() []*int {
m := make(map[*int]*int) // ERROR "make\(map\[\*int\]\*int\) does not escape"
// BAD: i should not escape
- i := 0 // ERROR "moved to heap: i"
- j := 0 // ERROR "moved to heap: j"
+ i := 0 // ERROR "moved to heap: i"
+ j := 0 // ERROR "moved to heap: j"
m[&i] = &j
var r []*int
for k, v := range m {
}
func map5(m map[*int]*int) { // ERROR "m does not escape"
- i := 0 // ERROR "moved to heap: i"
- j := 0 // ERROR "moved to heap: j"
+ i := 0 // ERROR "moved to heap: i"
+ j := 0 // ERROR "moved to heap: j"
m[&i] = &j
}
if m != nil {
m = make(map[*int]*int) // ERROR "make\(map\[\*int\]\*int\) does not escape"
}
- i := 0 // ERROR "moved to heap: i"
- j := 0 // ERROR "moved to heap: j"
+ i := 0 // ERROR "moved to heap: i"
+ j := 0 // ERROR "moved to heap: j"
m[&i] = &j
}
i := 0 // ERROR "moved to heap: i"
// BAD: j should not escape
j := 0 // ERROR "moved to heap: j"
- m := map[*int]*int{&i: &j} // ERROR "literal does not escape"
+ m := map[*int]*int{&i: &j} // ERROR "map\[\*int\]\*int{...} does not escape"
_ = m
}
func map8() {
i := 0 // ERROR "moved to heap: i"
j := 0 // ERROR "moved to heap: j"
- m := map[*int]*int{&i: &j} // ERROR "literal escapes to heap"
+ m := map[*int]*int{&i: &j} // ERROR "map\[\*int\]\*int{...} escapes to heap"
sink = m
}
// BAD: i should not escape
i := 0 // ERROR "moved to heap: i"
j := 0 // ERROR "moved to heap: j"
- m := map[*int]*int{&i: &j} // ERROR "literal does not escape"
+ m := map[*int]*int{&i: &j} // ERROR "map\[\*int\]\*int{...} does not escape"
return m[nil]
}
}
func caller0b() {
- i := 0 // ERROR "moved to heap: i$"
+ i := 0 // ERROR "moved to heap: i$"
sink = param0(&i)
}
}
func caller3b() {
- i := 0 // ERROR "moved to heap: i$"
- j := 0 // ERROR "moved to heap: j$"
+ i := 0 // ERROR "moved to heap: i$"
+ j := 0 // ERROR "moved to heap: j$"
p := Pair{&i, &j}
param3(&p)
- sink = p // ERROR "p escapes to heap$"
+ sink = p // ERROR "p escapes to heap$"
}
// in -> rcvr
i := 0 // ERROR "moved to heap: i$"
p := Pair{}
p.param4(&i)
- sink = p // ERROR "p escapes to heap$"
+ sink = p // ERROR "p escapes to heap$"
}
// in -> heap
}
func caller5() {
- i := 0 // ERROR "moved to heap: i$"
+ i := 0 // ERROR "moved to heap: i$"
param5(&i)
}
}
func caller6a() {
- i := 0 // ERROR "moved to heap: i$"
- p := &i // ERROR "moved to heap: p$"
+ i := 0 // ERROR "moved to heap: i$"
+ p := &i // ERROR "moved to heap: p$"
p2 := &p
param6(&p2)
}
}
func caller7() {
- i := 0 // ERROR "moved to heap: i$"
+ i := 0 // ERROR "moved to heap: i$"
p := &i
p2 := &p
param7(&p2)
}
func caller9b() {
- i := 0 // ERROR "moved to heap: i$"
- p := &i // ERROR "moved to heap: p$"
+ i := 0 // ERROR "moved to heap: i$"
+ p := &i // ERROR "moved to heap: p$"
p2 := &p
sink = param9(&p2)
}
}
func caller10b() {
- i := 0 // ERROR "moved to heap: i$"
+ i := 0 // ERROR "moved to heap: i$"
p := &i
p2 := &p
sink = param10(&p2)
}
func caller11a() {
- i := 0 // ERROR "moved to heap: i"
- p := &i // ERROR "moved to heap: p"
+ i := 0 // ERROR "moved to heap: i"
+ p := &i // ERROR "moved to heap: p"
_ = param11(&p)
}
func caller11b() {
- i := 0 // ERROR "moved to heap: i$"
- p := &i // ERROR "moved to heap: p$"
+ i := 0 // ERROR "moved to heap: i$"
+ p := &i // ERROR "moved to heap: p$"
sink = param11(&p)
}
func caller11c() { // GOOD
- i := 0 // ERROR "moved to heap: i$"
- p := &i // ERROR "moved to heap: p"
+ i := 0 // ERROR "moved to heap: i$"
+ p := &i // ERROR "moved to heap: p"
sink = *param11(&p)
}
func caller11d() {
- i := 0 // ERROR "moved to heap: i$"
- p := &i // ERROR "moved to heap: p"
+ i := 0 // ERROR "moved to heap: i$"
+ p := &i // ERROR "moved to heap: p"
p2 := &p
sink = param11(p2)
}
func caller12b() {
i := 0 // ERROR "moved to heap: i$"
p := &i // ERROR "moved to heap: p$"
- r := &Indir{} // ERROR "&Indir literal does not escape$"
+ r := &Indir{} // ERROR "&Indir{} does not escape$"
r.param12(&p)
_ = r
}
func caller13c() {
i := 0 // ERROR "moved to heap: i$"
var p *int
- v := &Val{&p} // ERROR "&Val literal does not escape$"
+ v := &Val{&p} // ERROR "&Val{...} does not escape$"
v.param13(&i)
_ = v
}
}
func caller13e() {
- i := 0 // ERROR "moved to heap: i$"
- var p *int // ERROR "moved to heap: p$"
+ i := 0 // ERROR "moved to heap: i$"
+ var p *int // ERROR "moved to heap: p$"
v := Val{&p}
v.param13(&i)
sink = v
func caller13f() {
i := 0 // ERROR "moved to heap: i$"
var p *int // ERROR "moved to heap: p$"
- v := &Val{&p} // ERROR "&Val literal escapes to heap$"
+ v := &Val{&p} // ERROR "&Val{...} escapes to heap$"
v.param13(&i)
sink = v
}
func caller13h() {
i := 0 // ERROR "moved to heap: i$"
var p *int
- v := &Val{&p} // ERROR "&Val literal does not escape$"
+ v := &Val{&p} // ERROR "&Val{...} does not escape$"
v.param13(&i)
- sink = **v.p // ERROR "\* \(\*v\.p\) escapes to heap"
+ sink = **v.p // ERROR "\* \(\*v\.p\) escapes to heap"
}
type Node struct {
var Sink *Node
func f(x *Node) { // ERROR "leaking param content: x"
- Sink = &Node{x.p} // ERROR "&Node literal escapes to heap"
+ Sink = &Node{x.p} // ERROR "&Node{...} escapes to heap"
}
func g(x *Node) *Node { // ERROR "leaking param content: x"
- return &Node{x.p} // ERROR "&Node literal escapes to heap"
+ return &Node{x.p} // ERROR "&Node{...} escapes to heap"
}
func h(x *Node) { // ERROR "leaking param: x"
- y := &Node{x} // ERROR "&Node literal does not escape"
+ y := &Node{x} // ERROR "&Node{...} does not escape"
Sink = g(y)
f(y)
}
func slice8() {
i := 0
- s := []*int{&i} // ERROR "literal does not escape"
+ s := []*int{&i} // ERROR "\[\]\*int{...} does not escape"
_ = s
}
func slice9() *int {
i := 0 // ERROR "moved to heap: i"
- s := []*int{&i} // ERROR "literal does not escape"
+ s := []*int{&i} // ERROR "\[\]\*int{...} does not escape"
return s[0]
}
func slice10() []*int {
i := 0 // ERROR "moved to heap: i"
- s := []*int{&i} // ERROR "literal escapes to heap"
+ s := []*int{&i} // ERROR "\[\]\*int{...} escapes to heap"
return s
}
func envForDir(dir string) []string { // ERROR "dir does not escape"
env := os.Environ()
- return mergeEnvLists([]string{"PWD=" + dir}, env) // ERROR ".PWD=. \+ dir escapes to heap" "\[\]string literal does not escape"
+ return mergeEnvLists([]string{"PWD=" + dir}, env) // ERROR ".PWD=. \+ dir escapes to heap" "\[\]string{...} does not escape"
}
func mergeEnvLists(in, out []string) []string { // ERROR "leaking param content: in" "leaking param content: out" "leaking param: out to result ~r2 level=0"
func setupTestData() {
resolveIPAddrTests = append(resolveIPAddrTests,
- []resolveIPAddrTest{ // ERROR "\[\]resolveIPAddrTest literal does not escape"
+ []resolveIPAddrTest{ // ERROR "\[\]resolveIPAddrTest{...} does not escape"
{"ip",
"localhost",
- &IPAddr{IP: IPv4(127, 0, 0, 1)}, // ERROR "&IPAddr literal escapes to heap"
+ &IPAddr{IP: IPv4(127, 0, 0, 1)}, // ERROR "&IPAddr{...} escapes to heap"
nil},
{"ip4",
"localhost",
- &IPAddr{IP: IPv4(127, 0, 0, 1)}, // ERROR "&IPAddr literal escapes to heap"
+ &IPAddr{IP: IPv4(127, 0, 0, 1)}, // ERROR "&IPAddr{...} escapes to heap"
nil},
}...)
}
}
func tSPPi() {
- s := "cat" // ERROR "moved to heap: s$"
+ s := "cat" // ERROR "moved to heap: s$"
ps := &s
pps := &ps
- pu := &U{ps, pps} // ERROR "&U literal does not escape$"
+ pu := &U{ps, pps} // ERROR "&U{...} does not escape$"
Ssink = pu.SPPi()
}
func tiSPP() {
- s := "cat" // ERROR "moved to heap: s$"
+ s := "cat" // ERROR "moved to heap: s$"
ps := &s
pps := &ps
- pu := &U{ps, pps} // ERROR "&U literal does not escape$"
+ pu := &U{ps, pps} // ERROR "&U{...} does not escape$"
Ssink = *pu.SPP()
}
// BAD: need fine-grained (field-sensitive) analysis to avoid spurious escape of ps
func tSP() {
- s := "cat" // ERROR "moved to heap: s$"
- ps := &s // ERROR "moved to heap: ps$"
+ s := "cat" // ERROR "moved to heap: s$"
+ ps := &s // ERROR "moved to heap: ps$"
pps := &ps
- pu := &U{ps, pps} // ERROR "&U literal does not escape$"
+ pu := &U{ps, pps} // ERROR "&U{...} does not escape$"
Ssink = pu.SP()
}
// BAD: need fine-grained (field-sensitive) analysis to avoid spurious escape of all but &s3
func tUPiSPa() {
s1 := "ant"
- s2 := "bat" // ERROR "moved to heap: s2$"
- s3 := "cat" // ERROR "moved to heap: s3$"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s2 := "bat" // ERROR "moved to heap: s2$"
+ s3 := "cat" // ERROR "moved to heap: s3$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
- ps4 := &s4 // ERROR "moved to heap: ps4$"
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps4 := &s4 // ERROR "moved to heap: ps4$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal escapes to heap$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} escapes to heap$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPa() // Ssink = &s3 (only &s3 really escapes)
}
// BAD: need fine-grained (field-sensitive) analysis to avoid spurious escape of all but &s3
func tUPiSPb() {
s1 := "ant"
- s2 := "bat" // ERROR "moved to heap: s2$"
- s3 := "cat" // ERROR "moved to heap: s3$"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s2 := "bat" // ERROR "moved to heap: s2$"
+ s3 := "cat" // ERROR "moved to heap: s3$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
- ps4 := &s4 // ERROR "moved to heap: ps4$"
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps4 := &s4 // ERROR "moved to heap: ps4$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal escapes to heap$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} escapes to heap$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPb() // Ssink = &s3 (only &s3 really escapes)
}
// BAD: need fine-grained (field-sensitive) analysis to avoid spurious escape of all but &s3
func tUPiSPc() {
s1 := "ant"
- s2 := "bat" // ERROR "moved to heap: s2$"
- s3 := "cat" // ERROR "moved to heap: s3$"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s2 := "bat" // ERROR "moved to heap: s2$"
+ s3 := "cat" // ERROR "moved to heap: s3$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
- ps4 := &s4 // ERROR "moved to heap: ps4$"
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps4 := &s4 // ERROR "moved to heap: ps4$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal escapes to heap$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} escapes to heap$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPc() // Ssink = &s3 (only &s3 really escapes)
}
// BAD: need fine-grained (field-sensitive) analysis to avoid spurious escape of all but &s3
func tUPiSPd() {
s1 := "ant"
- s2 := "bat" // ERROR "moved to heap: s2$"
- s3 := "cat" // ERROR "moved to heap: s3$"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s2 := "bat" // ERROR "moved to heap: s2$"
+ s3 := "cat" // ERROR "moved to heap: s3$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
- ps4 := &s4 // ERROR "moved to heap: ps4$"
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps4 := &s4 // ERROR "moved to heap: ps4$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal escapes to heap$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} escapes to heap$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPd() // Ssink = &s3 (only &s3 really escapes)
}
s1 := "ant"
s2 := "bat"
s3 := "cat"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
ps4 := &s4
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal does not escape$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} does not escape$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPPia() // Ssink = *&ps4 = &s4 (only &s4 really escapes)
}
s1 := "ant"
s2 := "bat"
s3 := "cat"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
ps4 := &s4
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal does not escape$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} does not escape$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPPib() // Ssink = *&ps4 = &s4 (only &s4 really escapes)
}
s1 := "ant"
s2 := "bat"
s3 := "cat"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
ps4 := &s4
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal does not escape$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} does not escape$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPPic() // Ssink = *&ps4 = &s4 (only &s4 really escapes)
}
s1 := "ant"
s2 := "bat"
s3 := "cat"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
ps4 := &s4
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal does not escape$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} does not escape$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPPid() // Ssink = *&ps4 = &s4 (only &s4 really escapes)
}
s3 := "cat"
s4 := "dog"
s5 := "emu"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
ps4 := &s4
ps6 := &s6
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal does not escape$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} does not escape$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPPiSPPia() // Ssink = *&ps6 = &s6 (only &s6 really escapes)
}
}
func tSPPi() {
- s := "cat" // ERROR "moved to heap: s$"
+ s := "cat" // ERROR "moved to heap: s$"
ps := &s
pps := &ps
- pu := &U{ps, pps} // ERROR "&U literal does not escape$"
+ pu := &U{ps, pps} // ERROR "&U{...} does not escape$"
Ssink = pu.SPPi()
}
func tiSPP() {
- s := "cat" // ERROR "moved to heap: s$"
+ s := "cat" // ERROR "moved to heap: s$"
ps := &s
pps := &ps
- pu := &U{ps, pps} // ERROR "&U literal does not escape$"
+ pu := &U{ps, pps} // ERROR "&U{...} does not escape$"
Ssink = *pu.SPP()
}
// BAD: need fine-grained analysis to avoid spurious escape of ps
func tSP() {
- s := "cat" // ERROR "moved to heap: s$"
- ps := &s // ERROR "moved to heap: ps$"
+ s := "cat" // ERROR "moved to heap: s$"
+ ps := &s // ERROR "moved to heap: ps$"
pps := &ps
- pu := &U{ps, pps} // ERROR "&U literal does not escape$"
+ pu := &U{ps, pps} // ERROR "&U{...} does not escape$"
Ssink = pu.SP()
}
// BAD: need fine-grained (field-sensitive) analysis to avoid spurious escape of all but &s3
func tUPiSPa() {
s1 := "ant"
- s2 := "bat" // ERROR "moved to heap: s2$"
- s3 := "cat" // ERROR "moved to heap: s3$"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s2 := "bat" // ERROR "moved to heap: s2$"
+ s3 := "cat" // ERROR "moved to heap: s3$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
- ps4 := &s4 // ERROR "moved to heap: ps4$"
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps4 := &s4 // ERROR "moved to heap: ps4$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal escapes to heap$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} escapes to heap$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPa() // Ssink = &s3 (only &s3 really escapes)
}
// BAD: need fine-grained (field-sensitive) analysis to avoid spurious escape of all but &s3
func tUPiSPb() {
s1 := "ant"
- s2 := "bat" // ERROR "moved to heap: s2$"
- s3 := "cat" // ERROR "moved to heap: s3$"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s2 := "bat" // ERROR "moved to heap: s2$"
+ s3 := "cat" // ERROR "moved to heap: s3$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
- ps4 := &s4 // ERROR "moved to heap: ps4$"
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps4 := &s4 // ERROR "moved to heap: ps4$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal escapes to heap$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} escapes to heap$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPb() // Ssink = &s3 (only &s3 really escapes)
}
// BAD: need fine-grained (field-sensitive) analysis to avoid spurious escape of all but &s3
func tUPiSPc() {
s1 := "ant"
- s2 := "bat" // ERROR "moved to heap: s2$"
- s3 := "cat" // ERROR "moved to heap: s3$"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s2 := "bat" // ERROR "moved to heap: s2$"
+ s3 := "cat" // ERROR "moved to heap: s3$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
- ps4 := &s4 // ERROR "moved to heap: ps4$"
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps4 := &s4 // ERROR "moved to heap: ps4$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal escapes to heap$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} escapes to heap$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPc() // Ssink = &s3 (only &s3 really escapes)
}
// BAD: need fine-grained (field-sensitive) analysis to avoid spurious escape of all but &s3
func tUPiSPd() {
s1 := "ant"
- s2 := "bat" // ERROR "moved to heap: s2$"
- s3 := "cat" // ERROR "moved to heap: s3$"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s2 := "bat" // ERROR "moved to heap: s2$"
+ s3 := "cat" // ERROR "moved to heap: s3$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
- ps4 := &s4 // ERROR "moved to heap: ps4$"
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps4 := &s4 // ERROR "moved to heap: ps4$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal escapes to heap$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} escapes to heap$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPd() // Ssink = &s3 (only &s3 really escapes)
}
s1 := "ant"
s2 := "bat"
s3 := "cat"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
ps4 := &s4
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal does not escape$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} does not escape$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPPia() // Ssink = *&ps4 = &s4 (only &s4 really escapes)
}
s1 := "ant"
s2 := "bat"
s3 := "cat"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
ps4 := &s4
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal does not escape$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} does not escape$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPPib() // Ssink = *&ps4 = &s4 (only &s4 really escapes)
}
s1 := "ant"
s2 := "bat"
s3 := "cat"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
ps4 := &s4
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal does not escape$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} does not escape$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPPic() // Ssink = *&ps4 = &s4 (only &s4 really escapes)
}
s1 := "ant"
s2 := "bat"
s3 := "cat"
- s4 := "dog" // ERROR "moved to heap: s4$"
- s5 := "emu" // ERROR "moved to heap: s5$"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s4 := "dog" // ERROR "moved to heap: s4$"
+ s5 := "emu" // ERROR "moved to heap: s5$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
ps4 := &s4
- ps6 := &s6 // ERROR "moved to heap: ps6$"
+ ps6 := &s6 // ERROR "moved to heap: ps6$"
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal does not escape$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} does not escape$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPiSPPid() // Ssink = *&ps4 = &s4 (only &s4 really escapes)
}
s3 := "cat"
s4 := "dog"
s5 := "emu"
- s6 := "fox" // ERROR "moved to heap: s6$"
+ s6 := "fox" // ERROR "moved to heap: s6$"
ps2 := &s2
ps4 := &s4
ps6 := &s6
u1 := U{&s1, &ps2}
- u2 := &U{&s3, &ps4} // ERROR "&U literal does not escape$"
- u3 := &U{&s5, &ps6} // ERROR "&U literal does not escape$"
- v := &V{u1, u2, &u3} // ERROR "&V literal does not escape$"
+ u2 := &U{&s3, &ps4} // ERROR "&U{...} does not escape$"
+ u3 := &U{&s5, &ps6} // ERROR "&U{...} does not escape$"
+ v := &V{u1, u2, &u3} // ERROR "&V{...} does not escape$"
Ssink = v.UPPiSPPia() // Ssink = *&ps6 = &s6 (only &s6 really escapes)
}
a := int32(1) // ERROR "moved to heap: a"
b := "cat"
c := &a
- fs := fakeSlice{3, &[4]interface{}{a, b, c, nil}} // ERROR "a escapes to heap" "b escapes to heap" "&\[4\]interface {} literal does not escape"
+ fs := fakeSlice{3, &[4]interface{}{a, b, c, nil}} // ERROR "a escapes to heap" "b escapes to heap" "&\[4\]interface {}{...} does not escape"
isink = FooK(fs)
}
a := int32(1) // ERROR "moved to heap: a"
b := "cat"
c := &a
- s := []interface{}{a, b, c} // ERROR "a escapes to heap" "b escapes to heap" "\[\]interface {} literal does not escape"
+ s := []interface{}{a, b, c} // ERROR "a escapes to heap" "b escapes to heap" "\[\]interface {}{...} does not escape"
isink = FooL(s)
}
var fn *str
for i := 0; i < maxI; i++ {
// var fn *str // this makes it work, because fn stays off heap
- fn = &str{m} // ERROR "&str literal escapes to heap"
+ fn = &str{m} // ERROR "&str{...} escapes to heap"
recur1(0, fn)
}
// var fn *str
for i := 0; i < maxI; i++ {
var fn *str // this makes it work, because fn stays off heap
- fn = &str{m} // ERROR "&str literal does not escape"
+ fn = &str{m} // ERROR "&str{...} does not escape"
recur1(0, fn)
}
func main() {
var s []int
- var _ string = append(s, Foo{""}) // ERROR "cannot use .. \(type untyped string\) as type int in field value" "cannot use Foo literal \(type Foo\) as type int in append" "cannot use append\(s\, Foo literal\) \(type \[\]int\) as type string in assignment"
+ var _ string = append(s, Foo{""}) // ERROR "cannot use .. \(type untyped string\) as type int in field value" "cannot use Foo{...} \(type Foo\) as type int in append" "cannot use append\(s\, Foo{...}\) \(type \[\]int\) as type string in assignment"
}
func F1() {
var s S
for i := 0; i < N; i++ {
- fs := []func(){ // ERROR "\[\]func\(\) literal does not escape"
+ fs := []func(){ // ERROR "\[\]func\(\){...} does not escape"
s.Inc, // ERROR "s.Inc does not escape"
}
for _, f := range fs {
func F2() {
var s S
for i := 0; i < N; i++ {
- for _, f := range []func(){ // ERROR "\[\]func\(\) literal does not escape"
+ for _, f := range []func(){ // ERROR "\[\]func\(\){...} does not escape"
s.Inc, // ERROR "s.Inc does not escape"
} {
f()
_ = Foo{
1,
2,
- 3, // ERROR "too few values in Foo literal"
+ 3, // ERROR "too few values in Foo{...}"
}
_ = Foo{
1,
2,
3,
- Bar{"A", "B"}, // ERROR "too many values in Bar literal"
+ Bar{"A", "B"}, // ERROR "too many values in Bar{...}"
}
_ = Foo{
1,
2,
- Bar{"A", "B"}, // ERROR "too many values in Bar literal" "too few values in Foo literal"
+ Bar{"A", "B"}, // ERROR "too many values in Bar{...}" "too few values in Foo{...}"
}
}
type T struct{}
var _ = S{
- f: &T{}, // ERROR "cannot use &T literal"
+ f: &T{}, // ERROR "cannot use &T{}"
}
var _ = P{
- f: T{}, // ERROR "cannot use T literal"
+ f: T{}, // ERROR "cannot use T{}"
}
func bar() { // ERROR "can inline bar"
value := 10
- debugf("value is %d", value) // ERROR "inlining call to debugf" "value does not escape" "\[\]interface {} literal does not escape"
+ debugf("value is %d", value) // ERROR "inlining call to debugf" "value does not escape" "\[\]interface {}{...} does not escape"
}
defer f(new(int), new(int)) // ERROR "... argument does not escape$" "new\(int\) does not escape$"
defer f(nil...)
- defer f([]*int{}...) // ERROR "\[\]\*int literal does not escape$"
- defer f([]*int{new(int)}...) // ERROR "\[\]\*int literal does not escape$" "new\(int\) does not escape$"
- defer f([]*int{new(int), new(int)}...) // ERROR "\[\]\*int literal does not escape$" "new\(int\) does not escape$"
+ defer f([]*int{}...) // ERROR "\[\]\*int{} does not escape$"
+ defer f([]*int{new(int)}...) // ERROR "\[\]\*int{...} does not escape$" "new\(int\) does not escape$"
+ defer f([]*int{new(int), new(int)}...) // ERROR "\[\]\*int{...} does not escape$" "new\(int\) does not escape$"
go f()
go f(new(int)) // ERROR "... argument escapes to heap$" "new\(int\) escapes to heap$"
go f(new(int), new(int)) // ERROR "... argument escapes to heap$" "new\(int\) escapes to heap$"
go f(nil...)
- go f([]*int{}...) // ERROR "\[\]\*int literal escapes to heap$"
- go f([]*int{new(int)}...) // ERROR "\[\]\*int literal escapes to heap$" "new\(int\) escapes to heap$"
- go f([]*int{new(int), new(int)}...) // ERROR "\[\]\*int literal escapes to heap$" "new\(int\) escapes to heap$"
+ go f([]*int{}...) // ERROR "\[\]\*int{} escapes to heap$"
+ go f([]*int{new(int)}...) // ERROR "\[\]\*int{...} escapes to heap$" "new\(int\) escapes to heap$"
+ go f([]*int{new(int), new(int)}...) // ERROR "\[\]\*int{...} escapes to heap$" "new\(int\) escapes to heap$"
for {
defer f()
defer f(new(int), new(int)) // ERROR "... argument escapes to heap$" "new\(int\) escapes to heap$"
defer f(nil...)
- defer f([]*int{}...) // ERROR "\[\]\*int literal escapes to heap$"
- defer f([]*int{new(int)}...) // ERROR "\[\]\*int literal escapes to heap$" "new\(int\) escapes to heap$"
- defer f([]*int{new(int), new(int)}...) // ERROR "\[\]\*int literal escapes to heap$" "new\(int\) escapes to heap$"
+ defer f([]*int{}...) // ERROR "\[\]\*int{} escapes to heap$"
+ defer f([]*int{new(int)}...) // ERROR "\[\]\*int{...} escapes to heap$" "new\(int\) escapes to heap$"
+ defer f([]*int{new(int), new(int)}...) // ERROR "\[\]\*int{...} escapes to heap$" "new\(int\) escapes to heap$"
go f()
go f(new(int)) // ERROR "... argument escapes to heap$" "new\(int\) escapes to heap$"
go f(new(int), new(int)) // ERROR "... argument escapes to heap$" "new\(int\) escapes to heap$"
go f(nil...)
- go f([]*int{}...) // ERROR "\[\]\*int literal escapes to heap$"
- go f([]*int{new(int)}...) // ERROR "\[\]\*int literal escapes to heap$" "new\(int\) escapes to heap$"
- go f([]*int{new(int), new(int)}...) // ERROR "\[\]\*int literal escapes to heap$" "new\(int\) escapes to heap$"
+ go f([]*int{}...) // ERROR "\[\]\*int{} escapes to heap$"
+ go f([]*int{new(int)}...) // ERROR "\[\]\*int{...} escapes to heap$" "new\(int\) escapes to heap$"
+ go f([]*int{new(int), new(int)}...) // ERROR "\[\]\*int{...} escapes to heap$" "new\(int\) escapes to heap$"
}
}
--- /dev/null
+// errorcheck
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+type t struct{ x int }
+
+func f1() {
+ t{}.M() // ERROR "t{}.M undefined \(type t has no field or method M\)"
+ t{x: 1}.M() // ERROR "t{...}.M undefined \(type t has no field or method M\)"
+}
+
+func f2() (*t, error) {
+ // BAD: should report undefined error only.
+ return t{}.M() // ERROR "t{}.M undefined \(type t has no field or method M\)" "not enough arguments to return"
+}
}
func x() {
- x := t{}.f // ERROR "t literal.f escapes to heap"
+ x := t{}.f // ERROR "t{}.f escapes to heap"
x()
}
func y() {
var i int // ERROR "moved to heap: i"
- y := (&t{&i}).f // ERROR "\(&t literal\).f escapes to heap" "&t literal escapes to heap"
+ y := (&t{&i}).f // ERROR "\(&t{...}\).f escapes to heap" "&t{...} escapes to heap"
y()
}
func z() {
var i int // ERROR "moved to heap: i"
- z := t{&i}.f // ERROR "t literal.f escapes to heap"
+ z := t{&i}.f // ERROR "t{...}.f escapes to heap"
z()
}
package p
func f() [2]int {
- return [...]int{2: 0} // ERROR "cannot use \[\.\.\.\]int literal \(type \[3\]int\)"
+ return [...]int{2: 0} // ERROR "cannot use \[\.\.\.\]int{...} \(type \[3\]int\)"
}
// can be stack-allocated.
var b bytes.Buffer
b.WriteString("123")
- b.Write([]byte{'4'}) // ERROR "\[\]byte literal does not escape$"
+ b.Write([]byte{'4'}) // ERROR "\[\]byte{...} does not escape$"
return b.String() // ERROR "inlining call to bytes.\(\*Buffer\).String$" "string\(bytes.b.buf\[bytes.b.off:\]\) escapes to heap$"
}
func bufferNoEscape2(xs []string) int { // ERROR "xs does not escape$"
- b := bytes.NewBuffer(make([]byte, 0, 64)) // ERROR "&bytes.Buffer literal does not escape$" "make\(\[\]byte, 0, 64\) does not escape$" "inlining call to bytes.NewBuffer$"
+ b := bytes.NewBuffer(make([]byte, 0, 64)) // ERROR "&bytes.Buffer{...} does not escape$" "make\(\[\]byte, 0, 64\) does not escape$" "inlining call to bytes.NewBuffer$"
for _, x := range xs {
b.WriteString(x)
}
}
func bufferNoEscape3(xs []string) string { // ERROR "xs does not escape$"
- b := bytes.NewBuffer(make([]byte, 0, 64)) // ERROR "&bytes.Buffer literal does not escape$" "make\(\[\]byte, 0, 64\) does not escape$" "inlining call to bytes.NewBuffer$"
+ b := bytes.NewBuffer(make([]byte, 0, 64)) // ERROR "&bytes.Buffer{...} does not escape$" "make\(\[\]byte, 0, 64\) does not escape$" "inlining call to bytes.NewBuffer$"
for _, x := range xs {
b.WriteString(x)
b.WriteByte(',')
func bufferNoEscape4() []byte {
var b bytes.Buffer
- b.Grow(64) // ERROR "bufferNoEscape4 ignoring self-assignment in bytes.b.buf = bytes.b.buf\[:bytes.m·3\]$" "inlining call to bytes.\(\*Buffer\).Grow$"
+ b.Grow(64) // ERROR "bufferNoEscape4 ignoring self-assignment in bytes.b.buf = bytes.b.buf\[:bytes.m·3\]$" "inlining call to bytes.\(\*Buffer\).Grow$"
useBuffer(&b)
return b.Bytes() // ERROR "inlining call to bytes.\(\*Buffer\).Bytes$"
}
func bufferNoEscape5() { // ERROR "can inline bufferNoEscape5$"
- b := bytes.NewBuffer(make([]byte, 0, 128)) // ERROR "&bytes.Buffer literal does not escape$" "make\(\[\]byte, 0, 128\) does not escape$" "inlining call to bytes.NewBuffer$"
+ b := bytes.NewBuffer(make([]byte, 0, 128)) // ERROR "&bytes.Buffer{...} does not escape$" "make\(\[\]byte, 0, 128\) does not escape$" "inlining call to bytes.NewBuffer$"
useBuffer(b)
}
}
func f() string { // ERROR "can inline f"
- x := head("hello", "world") // ERROR "inlining call to head" "\[\]string literal does not escape"
+ x := head("hello", "world") // ERROR "inlining call to head" "\[\]string{...} does not escape"
return x
}