aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2020-12-03 13:32:11 -0500
committerCherry Zhang <cherryyz@google.com>2020-12-03 21:34:39 +0000
commit37a32a1833a6e55baaa8d971406094148e42f7d1 (patch)
tree9cbb7c2c0e7f47dd9928b79d1f8482b683e98121 /test
parentb78b427be5e4c8a51a2b01b39c1ce6c4f39a93dc (diff)
downloadgo-37a32a1833a6e55baaa8d971406094148e42f7d1.tar.gz
go-37a32a1833a6e55baaa8d971406094148e42f7d1.zip
cmd/compile: make sure address of offset(SP) is rematerializeable
An address of offset(SP) may point to the callee args area, and may be used to move things into/out of the args/results. If an address like that is spilled and picked up by the GC, it may hold an arg/result live in the callee, which may not actually be live (e.g. a result not initialized at function entry). Make sure they are rematerializeable, so they are always short-lived and never picked up by the GC. This CL changes 386, PPC64, and Wasm. On AMD64 we already have the rule (line 2159). On other architectures, we already have similar rules like (OffPtr [off] ptr:(SP)) => (MOVDaddr [int32(off)] ptr) to avoid this problem. (Probably me in the past had run into this...) Fixes #42944. Change-Id: Id2ec73ac08f8df1829a9a7ceb8f749d67fe86d1e Reviewed-on: https://go-review.googlesource.com/c/go/+/275174 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue42944.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/fixedbugs/issue42944.go b/test/fixedbugs/issue42944.go
new file mode 100644
index 0000000000..bb947bc609
--- /dev/null
+++ b/test/fixedbugs/issue42944.go
@@ -0,0 +1,24 @@
+// errorcheck -0 -live
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 42944: address of callee args area should only be short-lived
+// and never across a call.
+
+package p
+
+type T [10]int // trigger DUFFCOPY when passing by value, so it uses the address
+
+func F() {
+ var x T
+ var i int
+ for {
+ x = G(i) // no autotmp live at this and next calls
+ H(i, x)
+ }
+}
+
+func G(int) T
+func H(int, T)