Commit a69754e3 authored by Keith Randall's avatar Keith Randall Committed by Keith Randall

cmd/compile: unnamed parameters do not escape

Fixes #19687

Change-Id: I2e4769b4ec5812506df4ac5dc6bc6a7c5774ecb0
Reviewed-on: https://go-review.googlesource.com/38600
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 7202341d
......@@ -2118,4 +2118,13 @@ func (e *EscState) esctag(fn *Node) {
case EscHeap: // touched by escflood, moved to heap
}
}
// Unnamed parameters are unused and therefore do not escape.
// (Unnamed parameters are not in the Dcl list in the loop above
// so we need to mark them separately.)
for _, f := range fn.Type.Params().Fields().Slice() {
if f.Sym == nil || isblanksym(f.Sym) {
f.Note = mktag(EscNone)
}
}
}
......@@ -9,6 +9,8 @@
package foo
import "runtime"
func noleak(p *int) int { // ERROR "p does not escape"
return *p
}
......@@ -149,3 +151,15 @@ func f10() {
var y = make([]byte, 1<<30) // ERROR "make\(\[\]byte, 1 << 30\) escapes to heap"
_ = x[0] + y[0]
}
// Test for issue 19687 (passing to unnamed parameters does not escape).
func f11(**int) {
}
func f12(_ **int) {
}
func f13() {
var x *int
f11(&x) // ERROR "&x does not escape"
f12(&x) // ERROR "&x does not escape"
runtime.KeepAlive(&x) // ERROR "&x does not escape"
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment