mirror of
https://github.com/golang/go
synced 2024-11-02 11:50:30 +00:00
cmd/compile, cmd/cgo: align complex{64,128} like GCC
complex64 and complex128 are treated like [2]float32 and [2]float64, so it makes sense to align them the same way. Change-Id: Ic614bcdcc91b080aeb1ad1fed6fc15ba5a2971f8 Reviewed-on: https://go-review.googlesource.com/19800 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
30088ac9a3
commit
f54c0db859
4 changed files with 32 additions and 4 deletions
24
misc/cgo/test/complex.go
Normal file
24
misc/cgo/test/complex.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
package cgotest
|
||||
|
||||
/*
|
||||
struct {
|
||||
float x;
|
||||
_Complex float y;
|
||||
} cplxAlign = { 3.14, 2.17 };
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestComplexAlign(t *testing.T) {
|
||||
if C.cplxAlign.x != 3.14 {
|
||||
t.Errorf("got %v, expected 3.14", C.cplxAlign.x)
|
||||
}
|
||||
if C.cplxAlign.y != 2.17 {
|
||||
t.Errorf("got %v, expected 2.17", C.cplxAlign.y)
|
||||
}
|
||||
}
|
|
@ -1641,7 +1641,7 @@ func (c *typeConv) Type(dtype dwarf.Type, pos token.Pos) *Type {
|
|||
case 16:
|
||||
t.Go = c.complex128
|
||||
}
|
||||
if t.Align = t.Size; t.Align >= c.ptrSize {
|
||||
if t.Align = t.Size / 2; t.Align >= c.ptrSize {
|
||||
t.Align = c.ptrSize
|
||||
}
|
||||
|
||||
|
|
|
@ -1232,8 +1232,8 @@ var goTypes = map[string]*Type{
|
|||
"uint64": {Size: 8, Align: 8, C: c("GoUint64")},
|
||||
"float32": {Size: 4, Align: 4, C: c("GoFloat32")},
|
||||
"float64": {Size: 8, Align: 8, C: c("GoFloat64")},
|
||||
"complex64": {Size: 8, Align: 8, C: c("GoComplex64")},
|
||||
"complex128": {Size: 16, Align: 16, C: c("GoComplex128")},
|
||||
"complex64": {Size: 8, Align: 4, C: c("GoComplex64")},
|
||||
"complex128": {Size: 16, Align: 8, C: c("GoComplex128")},
|
||||
}
|
||||
|
||||
// Map an ast type to a Type.
|
||||
|
|
|
@ -169,10 +169,14 @@ func dowidth(t *Type) {
|
|||
case TINT32, TUINT32, TFLOAT32:
|
||||
w = 4
|
||||
|
||||
case TINT64, TUINT64, TFLOAT64, TCOMPLEX64:
|
||||
case TINT64, TUINT64, TFLOAT64:
|
||||
w = 8
|
||||
t.Align = uint8(Widthreg)
|
||||
|
||||
case TCOMPLEX64:
|
||||
w = 8
|
||||
t.Align = 4
|
||||
|
||||
case TCOMPLEX128:
|
||||
w = 16
|
||||
t.Align = uint8(Widthreg)
|
||||
|
|
Loading…
Reference in a new issue