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>
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)
+ }
+ }
}
package foo
+import "runtime"
+
func noleak(p *int) int { // ERROR "p does not escape"
return *p
}
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"
+}