1
0
mirror of https://github.com/golang/go synced 2024-11-05 21:36:12 -07:00
go/test/fixedbugs/issue42944.go
Cherry Zhang 37a32a1833 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>
2020-12-03 21:34:39 +00:00

25 lines
513 B
Go

// 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)