aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-04-20 11:14:36 -0700
committerMatthew Dempsky <mdempsky@google.com>2020-04-21 20:49:34 +0000
commit2a2423bd05da85dc7d0f8e7d12531623b69036a0 (patch)
tree0d92bc832877e14b3653f924cdc4f39c9ce11270 /test
parent181153369534c6987306c47630f9e4fbf07b467f (diff)
downloadgo-2a2423bd05da85dc7d0f8e7d12531623b69036a0.tar.gz
go-2a2423bd05da85dc7d0f8e7d12531623b69036a0.zip
cmd/compile: more precise analysis of method values
Previously for a method value "x.M", we always flowed x directly to the heap, which led to the receiver argument generally needing to be heap allocated. This CL changes it to flow x to the closure and M's receiver parameter. This allows receiver arguments to be stack allocated as long as (1) the closure never escapes, *and* (2) method doesn't leak its receiver parameter. Within the standard library, this allows a handful of objects to be stack allocated instead. Listed here are diagnostics that were previously emitted by "go build -gcflags=-m std cmd" that are no longer emitted: archive/tar/writer.go:118:6: moved to heap: f archive/tar/writer.go:208:6: moved to heap: f archive/tar/writer.go:248:6: moved to heap: f cmd/compile/internal/gc/initorder.go:252:2: moved to heap: d cmd/compile/internal/gc/initorder.go:75:2: moved to heap: s cmd/go/internal/generate/generate.go:206:7: &Generator literal escapes to heap cmd/internal/obj/arm64/asm7.go:910:2: moved to heap: c cmd/internal/obj/mips/asm0.go:415:2: moved to heap: c cmd/internal/obj/pcln.go:294:22: new(pcinlineState) escapes to heap cmd/internal/obj/s390x/asmz.go:459:2: moved to heap: c crypto/tls/handshake_server.go:56:2: moved to heap: hs Thanks to Cuong Manh Le for help coming up with this solution. Fixes #27557. Change-Id: I8c85d671d07fb9b53e11d2dd05949a34dbbd7e17 Reviewed-on: https://go-review.googlesource.com/c/go/+/228263 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'test')
-rw-r--r--test/escape2.go3
-rw-r--r--test/escape2n.go3
-rw-r--r--test/fixedbugs/issue21709.go6
-rw-r--r--test/fixedbugs/issue27557.go3
4 files changed, 5 insertions, 10 deletions
diff --git a/test/escape2.go b/test/escape2.go
index 4e30331380..cf24f4bebc 100644
--- a/test/escape2.go
+++ b/test/escape2.go
@@ -1386,8 +1386,7 @@ func (t *Tm) M() { // ERROR "t does not escape$"
func foo141() {
var f func()
- // BAD: new(Tm) should not escape
- t := new(Tm) // ERROR "new\(Tm\) escapes to heap$"
+ t := new(Tm) // ERROR "new\(Tm\) does not escape$"
f = t.M // ERROR "t.M does not escape$"
_ = f
}
diff --git a/test/escape2n.go b/test/escape2n.go
index 26b0a1d8c5..f771e0aef2 100644
--- a/test/escape2n.go
+++ b/test/escape2n.go
@@ -1386,8 +1386,7 @@ func (t *Tm) M() { // ERROR "t does not escape$"
func foo141() {
var f func()
- // BAD: new(Tm) should not escape
- t := new(Tm) // ERROR "new\(Tm\) escapes to heap$"
+ t := new(Tm) // ERROR "new\(Tm\) does not escape$"
f = t.M // ERROR "t.M does not escape$"
_ = f
}
diff --git a/test/fixedbugs/issue21709.go b/test/fixedbugs/issue21709.go
index abc9e767e5..cc5896ab53 100644
--- a/test/fixedbugs/issue21709.go
+++ b/test/fixedbugs/issue21709.go
@@ -14,8 +14,7 @@ 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"
+ var s S
for i := 0; i < N; i++ {
fs := []func(){ // ERROR "\[\]func\(\) literal does not escape"
s.Inc, // ERROR "s.Inc does not escape"
@@ -27,8 +26,7 @@ func F1() {
}
func F2() {
- // BAD: s should not escape
- var s S // ERROR "moved to heap: s"
+ var s 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"
diff --git a/test/fixedbugs/issue27557.go b/test/fixedbugs/issue27557.go
index 11a23f6932..e35ab5a169 100644
--- a/test/fixedbugs/issue27557.go
+++ b/test/fixedbugs/issue27557.go
@@ -9,8 +9,7 @@ package p
var sink interface{}
func _() {
- // BAD: t should not escape
- var t T // ERROR "moved to heap"
+ var t T
f := t.noescape // ERROR "t.noescape does not escape"
f()
}