mirror of
https://github.com/golang/go
synced 2024-11-17 22:24:47 -07:00
f346a4c44c
This commit just adds a regress test for a few of the important corner cases that I identified in #27557, which turn out to not be tested anywhere. While here, annotate a few of the existing test cases where we could improve escape analysis. Updates #27557. Change-Id: Ie57792a538f7899bb17915485fabc86100f469a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/197137 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
40 lines
829 B
Go
40 lines
829 B
Go
// errorcheck -0 -l -m
|
|
|
|
// Copyright 2017 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.
|
|
|
|
// Issue 21709: range expression overly escapes.
|
|
|
|
package p
|
|
|
|
type S struct{}
|
|
|
|
func (s *S) Inc() {} // ERROR "s does not escape"
|
|
var N int
|
|
|
|
func F1() {
|
|
// BAD: s should not escape
|
|
var s S // ERROR "moved to heap: s"
|
|
for i := 0; i < N; i++ {
|
|
fs := []func(){ // ERROR "\[\]func\(\) literal does not escape"
|
|
s.Inc, // ERROR "s.Inc does not escape"
|
|
}
|
|
for _, f := range fs {
|
|
f()
|
|
}
|
|
}
|
|
}
|
|
|
|
func F2() {
|
|
// BAD: s should not escape
|
|
var s S // ERROR "moved to heap: s"
|
|
for i := 0; i < N; i++ {
|
|
for _, f := range []func(){ // ERROR "\[\]func\(\) literal does not escape"
|
|
s.Inc, // ERROR "s.Inc does not escape"
|
|
} {
|
|
f()
|
|
}
|
|
}
|
|
}
|