Skip to content

Commit

Permalink
cmd/compile: skip escape analysis diagnostics for OADDR
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mdempsky committed Apr 2, 2019
1 parent 4ebc651 commit abefcac
Show file tree
Hide file tree
Showing 31 changed files with 643 additions and 643 deletions.
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/gc/esc.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func escAnalyze(all []*Node, recursive bool) {

if Debug['m'] != 0 {
for _, n := range e.noesc {
if n.Esc == EscNone {
if n.Esc == EscNone && n.Op != OADDR {
Warnl(n.Pos, "%v %S does not escape", e.curfnSym(n), n)
}
}
Expand Down Expand Up @@ -1894,7 +1894,7 @@ func (e *EscState) escwalkBody(level Level, dst *Node, src *Node, step *EscStep,
}
if leaks {
src.Esc = EscHeap
if Debug['m'] != 0 && osrcesc != src.Esc {
if Debug['m'] != 0 && osrcesc != src.Esc && src.Op != OADDR {
p := src
if p.Left.Op == OCLOSURE {
p = p.Left // merely to satisfy error messages in tests
Expand Down
6 changes: 3 additions & 3 deletions test/closure3.dir/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func main() {
func() { // ERROR "func literal does not escape"
func() { // ERROR "can inline main.func24"
a = 2
}() // ERROR "inlining call to main.func24" "&a does not escape"
}() // ERROR "inlining call to main.func24"
}()
if a != 2 {
ppanic("a != 2")
Expand All @@ -220,7 +220,7 @@ func main() {
func(b int) { // ERROR "func literal does not escape"
func() { // ERROR "can inline main.func25.1"
b = 3
}() // ERROR "inlining call to main.func25.1" "&b does not escape"
}() // ERROR "inlining call to main.func25.1"
if b != 3 {
ppanic("b != 3")
}
Expand Down Expand Up @@ -272,7 +272,7 @@ func main() {
a = a * x
b = b * y
c = c * z
}(10) // ERROR "inlining call to main.func28.1.1" "&a does not escape" "&b does not escape" "&c does not escape"
}(10) // ERROR "inlining call to main.func28.1.1"
return a + c
}(100) + b
}(1000); r != 2350 {
Expand Down
Loading

0 comments on commit abefcac

Please sign in to comment.