Skip to content

Commit abefcac

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 4ebc651 commit abefcac

31 files changed

+643
-643
lines changed

src/cmd/compile/internal/gc/esc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func escAnalyze(all []*Node, recursive bool) {
399399

400400
if Debug['m'] != 0 {
401401
for _, n := range e.noesc {
402-
if n.Esc == EscNone {
402+
if n.Esc == EscNone && n.Op != OADDR {
403403
Warnl(n.Pos, "%v %S does not escape", e.curfnSym(n), n)
404404
}
405405
}
@@ -1894,7 +1894,7 @@ func (e *EscState) escwalkBody(level Level, dst *Node, src *Node, step *EscStep,
18941894
}
18951895
if leaks {
18961896
src.Esc = EscHeap
1897-
if Debug['m'] != 0 && osrcesc != src.Esc {
1897+
if Debug['m'] != 0 && osrcesc != src.Esc && src.Op != OADDR {
18981898
p := src
18991899
if p.Left.Op == OCLOSURE {
19001900
p = p.Left // merely to satisfy error messages in tests

test/closure3.dir/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func main() {
208208
func() { // ERROR "func literal does not escape"
209209
func() { // ERROR "can inline main.func24"
210210
a = 2
211-
}() // ERROR "inlining call to main.func24" "&a does not escape"
211+
}() // ERROR "inlining call to main.func24"
212212
}()
213213
if a != 2 {
214214
ppanic("a != 2")
@@ -220,7 +220,7 @@ func main() {
220220
func(b int) { // ERROR "func literal does not escape"
221221
func() { // ERROR "can inline main.func25.1"
222222
b = 3
223-
}() // ERROR "inlining call to main.func25.1" "&b does not escape"
223+
}() // ERROR "inlining call to main.func25.1"
224224
if b != 3 {
225225
ppanic("b != 3")
226226
}
@@ -272,7 +272,7 @@ func main() {
272272
a = a * x
273273
b = b * y
274274
c = c * z
275-
}(10) // ERROR "inlining call to main.func28.1.1" "&a does not escape" "&b does not escape" "&c does not escape"
275+
}(10) // ERROR "inlining call to main.func28.1.1"
276276
return a + c
277277
}(100) + b
278278
}(1000); r != 2350 {

0 commit comments

Comments
 (0)