2019-07-25 13:54:03 -06:00
|
|
|
// errorcheck -0 -m -l
|
2015-02-19 06:27:32 -07:00
|
|
|
|
2016-04-10 15:32:26 -06:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
2015-02-19 06:27:32 -07:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Test escape analysis for interface conversions.
|
|
|
|
|
|
|
|
package escape
|
|
|
|
|
|
|
|
var sink interface{}
|
|
|
|
|
|
|
|
type M interface {
|
|
|
|
M()
|
|
|
|
}
|
|
|
|
|
|
|
|
func mescapes(m M) { // ERROR "leaking param: m"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
sink = m
|
2015-02-19 06:27:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func mdoesnotescape(m M) { // ERROR "m does not escape"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests for type stored directly in iface and with value receiver method.
|
|
|
|
type M0 struct {
|
|
|
|
p *int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (M0) M() {
|
|
|
|
}
|
|
|
|
|
|
|
|
func efaceEscape0() {
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M0{&i}
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
_ = x
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M0{&i}
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
|
|
|
sink = x
|
2015-02-19 06:27:32 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M0{&i}
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
v1 := x.(M0)
|
|
|
|
_ = v1
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M0{&i}
|
2015-02-19 06:27:32 -07:00
|
|
|
// BAD: v does not escape to heap here
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
v1 := x.(M0)
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
sink = v1
|
2015-02-19 06:27:32 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M0{&i}
|
2015-02-19 06:27:32 -07:00
|
|
|
// BAD: v does not escape to heap here
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
x.M()
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M0{&i}
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
mescapes(x)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M0{&i}
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
mdoesnotescape(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests for type stored indirectly in iface and with value receiver method.
|
|
|
|
type M1 struct {
|
|
|
|
p *int
|
|
|
|
x int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (M1) M() {
|
|
|
|
}
|
|
|
|
|
|
|
|
func efaceEscape1() {
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M1{&i, 0}
|
2015-02-19 06:27:32 -07:00
|
|
|
var x M = v // ERROR "v does not escape"
|
|
|
|
_ = x
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M1{&i, 0}
|
2015-02-19 06:27:32 -07:00
|
|
|
var x M = v // ERROR "v escapes to heap"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
sink = x
|
2015-02-19 06:27:32 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M1{&i, 0}
|
2015-02-19 06:27:32 -07:00
|
|
|
var x M = v // ERROR "v does not escape"
|
|
|
|
v1 := x.(M1)
|
|
|
|
_ = v1
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M1{&i, 0}
|
cmd/compile: update escape analysis tests for newescape
The new escape analysis implementation tries to emit debugging
diagnostics that are compatible with the existing implementation, but
there's a handful of cases that are easier to handle by updating the
test expectations instead.
For regress tests that need updating, the original file is copied to
oldescapeXXX.go.go with -newescape=false added to the //errorcheck
line, while the file is updated in place with -newescape=true and new
test requirements.
Notable test changes:
1) escape_because.go looks for a lot of detailed internal debugging
messages that are fairly particular to how esc.go works and that I
haven't attempted to port over to escape.go yet.
2) There are a lot of "leaking param: x to result ~r1 level=-1"
messages for code like
func(p *int) *T { return &T{p} }
that were simply wrong. Here &T must be heap allocated unconditionally
(because it's being returned); and since p is stored into it, p
escapes unconditionally too. esc.go incorrectly reports that p escapes
conditionally only if the returned pointer escaped.
3) esc.go used to print each "leaking param" analysis result as it
discovered them, which could lead to redundant messages (e.g., that a
param leaks at level=0 and level=1). escape.go instead prints
everything at the end, once it knows the shortest path to each sink.
4) esc.go didn't precisely model direct-interface types, resulting in
some values unnecessarily escaping to the heap when stored into
non-escaping interface values.
5) For functions written in assembly, esc.go only printed "does not
escape" messages, whereas escape.go prints "does not escape" or
"leaking param" as appropriate, consistent with the behavior for
functions written in Go.
6) 12 tests included "BAD" annotations identifying cases where esc.go
was unnecessarily heap allocating something. These are all fixed by
escape.go.
Updates #23109.
Change-Id: Iabc9eb14c94c9cadde3b183478d1fd54f013502f
Reviewed-on: https://go-review.googlesource.com/c/go/+/170447
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2019-04-02 15:44:13 -06:00
|
|
|
var x M = v // ERROR "efaceEscape1 v does not escape"
|
2015-02-19 06:27:32 -07:00
|
|
|
v1 := x.(M1)
|
|
|
|
sink = v1 // ERROR "v1 escapes to heap"
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M1{&i, 0}
|
2015-02-19 06:27:32 -07:00
|
|
|
// 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"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M1{&i, 0}
|
2015-02-19 06:27:32 -07:00
|
|
|
var x M = v // ERROR "v escapes to heap"
|
|
|
|
mescapes(x)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 12:58:33 -06:00
|
|
|
v := M1{&i, 0}
|
2015-02-19 06:27:32 -07:00
|
|
|
var x M = v // ERROR "v does not escape"
|
|
|
|
mdoesnotescape(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests for type stored directly in iface and with pointer receiver method.
|
|
|
|
type M2 struct {
|
|
|
|
p *int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*M2) M() {
|
|
|
|
}
|
|
|
|
|
|
|
|
func efaceEscape2() {
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 12:58:33 -06:00
|
|
|
v := &M2{&i} // ERROR "&M2 literal does not escape"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
_ = x
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := &M2{&i} // ERROR "&M2 literal escapes to heap"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
|
|
|
sink = x
|
2015-02-19 06:27:32 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 12:58:33 -06:00
|
|
|
v := &M2{&i} // ERROR "&M2 literal does not escape"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
v1 := x.(*M2)
|
|
|
|
_ = v1
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := &M2{&i} // ERROR "&M2 literal escapes to heap"
|
2015-02-19 06:27:32 -07:00
|
|
|
// BAD: v does not escape to heap here
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
v1 := x.(*M2)
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
sink = v1
|
2015-02-19 06:27:32 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := &M2{&i} // ERROR "&M2 literal does not escape"
|
2015-02-19 06:27:32 -07:00
|
|
|
// BAD: v does not escape to heap here
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
v1 := x.(*M2)
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
sink = *v1
|
2015-02-19 06:27:32 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := &M2{&i} // ERROR "&M2 literal does not escape"
|
2015-02-19 06:27:32 -07:00
|
|
|
// BAD: v does not escape to heap here
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
v1, ok := x.(*M2)
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
sink = *v1
|
2015-02-19 06:27:32 -07:00
|
|
|
_ = ok
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := &M2{&i} // ERROR "&M2 literal escapes to heap"
|
2015-02-19 06:27:32 -07:00
|
|
|
// BAD: v does not escape to heap here
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
x.M()
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2019-04-01 12:58:33 -06:00
|
|
|
v := &M2{&i} // ERROR "&M2 literal escapes to heap"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
mescapes(x)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0
|
2019-04-01 12:58:33 -06:00
|
|
|
v := &M2{&i} // ERROR "&M2 literal does not escape"
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x M = v
|
2015-02-19 06:27:32 -07:00
|
|
|
mdoesnotescape(x)
|
|
|
|
}
|
|
|
|
}
|
2015-07-30 10:31:18 -06:00
|
|
|
|
|
|
|
type T1 struct {
|
|
|
|
p *int
|
|
|
|
}
|
|
|
|
|
|
|
|
type T2 struct {
|
|
|
|
T1 T1
|
|
|
|
}
|
|
|
|
|
|
|
|
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{
|
|
|
|
T1: *(x.(*T1)), // ERROR "&T2 literal escapes to heap"
|
|
|
|
}
|
|
|
|
}
|
2016-02-13 23:39:16 -07:00
|
|
|
|
2016-07-13 12:29:39 -06:00
|
|
|
func dotTypeEscape2() { // #13805, #15796
|
2016-02-13 23:39:16 -07:00
|
|
|
{
|
|
|
|
i := 0
|
2016-07-13 12:29:39 -06:00
|
|
|
j := 0
|
2016-02-13 23:39:16 -07:00
|
|
|
var v int
|
2016-07-13 12:29:39 -06:00
|
|
|
var ok bool
|
2016-02-13 23:39:16 -07:00
|
|
|
var x interface{} = i // ERROR "i does not escape"
|
2016-07-13 12:29:39 -06:00
|
|
|
var y interface{} = j // ERROR "j does not escape"
|
|
|
|
|
2019-04-01 12:58:33 -06:00
|
|
|
*(&v) = x.(int)
|
|
|
|
*(&v), *(&ok) = y.(int)
|
2016-02-13 23:39:16 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0
|
2016-07-13 12:29:39 -06:00
|
|
|
j := 0
|
|
|
|
var ok bool
|
2016-02-13 23:39:16 -07:00
|
|
|
var x interface{} = i // ERROR "i does not escape"
|
2016-07-13 12:29:39 -06:00
|
|
|
var y interface{} = j // ERROR "j does not escape"
|
2016-02-13 23:39:16 -07:00
|
|
|
|
2016-07-13 12:29:39 -06:00
|
|
|
sink = x.(int) // ERROR "x.\(int\) escapes to heap"
|
2019-04-01 12:58:33 -06:00
|
|
|
sink, *(&ok) = y.(int)
|
2016-02-13 23:39:16 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
i := 0 // ERROR "moved to heap: i"
|
2016-07-13 12:29:39 -06:00
|
|
|
j := 0 // ERROR "moved to heap: j"
|
|
|
|
var ok bool
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
var x interface{} = &i
|
|
|
|
var y interface{} = &j
|
2016-07-13 12:29:39 -06:00
|
|
|
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
sink = x.(*int)
|
2019-04-01 12:58:33 -06:00
|
|
|
sink, *(&ok) = y.(*int)
|
2016-02-13 23:39:16 -07:00
|
|
|
}
|
|
|
|
}
|