mirror of
https://github.com/golang/go
synced 2024-11-22 18:54:44 -07:00
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: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
parent
7202341de9
commit
a69754e30c
@ -2118,4 +2118,13 @@ func (e *EscState) esctag(fn *Node) {
|
|||||||
case EscHeap: // touched by escflood, moved to heap
|
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
|
package foo
|
||||||
|
|
||||||
|
import "runtime"
|
||||||
|
|
||||||
func noleak(p *int) int { // ERROR "p does not escape"
|
func noleak(p *int) int { // ERROR "p does not escape"
|
||||||
return *p
|
return *p
|
||||||
}
|
}
|
||||||
@ -149,3 +151,15 @@ func f10() {
|
|||||||
var y = make([]byte, 1<<30) // ERROR "make\(\[\]byte, 1 << 30\) escapes to heap"
|
var y = make([]byte, 1<<30) // ERROR "make\(\[\]byte, 1 << 30\) escapes to heap"
|
||||||
_ = x[0] + y[0]
|
_ = 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"
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user