1
0
mirror of https://github.com/golang/go synced 2024-09-29 14:14:29 -06:00
go/test/fixedbugs/issue12588.go
Matthew Dempsky abefcac10a cmd/compile: skip escape analysis diagnostics for OADDR
For most nodes (e.g., OPTRLIT, OMAKESLICE, OCONVIFACE), escape
analysis prints "escapes to heap" or "does not escape" to indicate
whether that node's allocation can be heap or stack allocated.

These messages are also emitted for OADDR, even though OADDR does not
actually allocate anything itself. Moreover, it's redundant because
escape analysis already prints "moved to heap" diagnostics when an
OADDR node like "&x" causes x to require heap allocation.

Because OADDR nodes don't allocate memory, my escape analysis rewrite
doesn't naturally emit the "escapes to heap" / "does not escape"
diagnostics for them. It's also non-trivial to replicate the exact
semantics esc.go uses for OADDR.

Since there are so many of these messages, I'm disabling them in this
CL by themselves. I modified esc.go to suppress the Warnl calls
without any other behavior changes, and then used a shell script to
automatically remove any ERROR messages mentioned by run.go in
"missing error" or "no match for" lines.

Fixes #16300.
Updates #23109.

Change-Id: I3993e2743c3ff83ccd0893f4e73b366ff8871a57
Reviewed-on: https://go-review.googlesource.com/c/go/+/170319
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
2019-04-02 16:34:03 +00:00

89 lines
1.5 KiB
Go

// errorcheck -0 -m -l
// Copyright 2015 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.
// Tests escape analysis for range of arrays.
// Compiles but need not run. Inlining is disabled.
package main
type A struct {
b [3]uint64
}
type B struct {
b [3]*uint64
}
func f(a A) int {
for i, x := range &a.b {
if x != 0 {
return 64*i + int(x)
}
}
return 0
}
func g(a *A) int { // ERROR "g a does not escape"
for i, x := range &a.b {
if x != 0 {
return 64*i + int(x)
}
}
return 0
}
func h(a *B) *uint64 { // ERROR "leaking param: a to result ~r1 level=1"
for i, x := range &a.b {
if i == 0 {
return x
}
}
return nil
}
func h2(a *B) *uint64 { // ERROR "leaking param: a to result ~r1 level=1"
p := &a.b
for i, x := range p {
if i == 0 {
return x
}
}
return nil
}
// Seems like below should be level=1, not 0.
func k(a B) *uint64 { // ERROR "leaking param: a to result ~r1 level=0"
for i, x := range &a.b {
if i == 0 {
return x
}
}
return nil
}
var sink *uint64
func main() {
var a1, a2 A
var b1, b2, b3, b4 B
var x1, x2, x3, x4 uint64 // ERROR "moved to heap: x1" "moved to heap: x3"
b1.b[0] = &x1
b2.b[0] = &x2
b3.b[0] = &x3
b4.b[0] = &x4
f(a1)
g(&a2)
sink = h(&b1)
h(&b2)
sink = h2(&b1)
h2(&b4)
x1 = 17
println("*sink=", *sink) // Verify that sink addresses x1
x3 = 42
sink = k(b3)
println("*sink=", *sink) // Verify that sink addresses x3
}