1
0
mirror of https://github.com/golang/go synced 2024-11-23 18:10:04 -07:00
go/test/fixedbugs/issue54638.go
Cherry Mui 1211a62bdc cmd/compile: align stack offset to alignment larger than PtrSize
In typebits.Set we check that the offset is a multiple of the
alignment, which makes perfect sense. But for values like
atomic.Int64, which has 8-byte alignment even on 32-bit platforms
(i.e. the alignment is larger than PtrSize), if it is on stack it
may be under-aligned, as the stack frame is only PtrSize aligned.

Normally we would prevent such values on stack, as the escape
analysis force values with higher alignment to heap. But for a
composite literal assignment like x = AlignedType{...}, the
compiler creates an autotmp for the RHS then copies it to the LHS.
The autotmp is on stack and may be under-aligned. Currently this
may cause an ICE in the typebits.Set check.

This CL makes it align the _offset_ of the autotmp to 8 bytes,
which satisfies the check. Note that this is actually lying: the
actual address at run time may not necessarily be 8-byte
aligned as we only align SP to 4 bytes.

The under-alignment is probably okay. The only purpose for the
autotmp is to copy the value to the LHS, and the copying code we
generate (at least currently) doesn't care the alignment beyond
stack alignment.

Fixes #54638.

Change-Id: I13c16afde2eea017479ff11dfc24092bcb8aba6a
Reviewed-on: https://go-review.googlesource.com/c/go/+/425256
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-26 15:24:31 +00:00

41 lines
601 B
Go

// compile
// Copyright 2022 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 54638: composite literal assignment with
// alignment > PtrSize causes ICE.
package p
import "sync/atomic"
type S struct{ l any }
type T struct {
H any
a [14]int64
f func()
x atomic.Int64
}
//go:noinline
func (T) M(any) {}
type W [2]int64
//go:noinline
func (W) Done() {}
func F(l any) [3]*int {
var w W
var x [3]*int // use some stack
t := T{H: S{l: l}}
go func() {
t.M(l)
w.Done()
}()
return x
}