aboutsummaryrefslogtreecommitdiff
path: root/test/escape5.go
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2018-12-04 15:54:14 -0500
committerCherry Zhang <cherryyz@google.com>2018-12-04 23:01:00 +0000
commitbe09bdf589a5c25e5d8b68a546e9b84bc1a1977b (patch)
treef8ca2d62b7d3a2200a9b584759ae824e96b08a15 /test/escape5.go
parent8a5797a00e0bbe483e88aab4830e8854af55b508 (diff)
downloadgo-be09bdf589a5c25e5d8b68a546e9b84bc1a1977b.tar.gz
go-be09bdf589a5c25e5d8b68a546e9b84bc1a1977b.zip
cmd/compile: fix unnamed parameter handling in escape analysis
For recursive functions, the parameters were iterated using fn.Name.Defn.Func.Dcl, which does not include unnamed/blank parameters. This results in a mismatch in formal-actual assignments, for example, func f(_ T, x T) f(a, b) should result in { _=a, x=b }, but the escape analysis currently sees only { x=a } and drops b on the floor. This may cause b to not escape when it should (or a escape when it should not). Fix this by using fntype.Params().FieldSlice() instead, which does include unnamed parameters. Also add a sanity check that ensures all the actual parameters are consumed. Fixes #29000 Change-Id: Icd86f2b5d71e7ebbab76e375b7702f62efcf59ae Reviewed-on: https://go-review.googlesource.com/c/152617 Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/escape5.go')
-rw-r--r--test/escape5.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/escape5.go b/test/escape5.go
index 03283a37f8..e26ecd5275 100644
--- a/test/escape5.go
+++ b/test/escape5.go
@@ -228,3 +228,20 @@ func f15730c(args ...interface{}) { // ERROR "leaking param content: args"
}
}
}
+
+// Issue 29000: unnamed parameter is not handled correctly
+
+var sink4 interface{}
+var alwaysFalse = false
+
+func f29000(_ int, x interface{}) { // ERROR "leaking param: x"
+ sink4 = x
+ if alwaysFalse {
+ g29000()
+ }
+}
+
+func g29000() {
+ x := 1
+ f29000(2, x) // ERROR "x escapes to heap"
+}