]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile, cmd/cgo: align complex{64,128} like GCC
authorMatthew Dempsky <mdempsky@google.com>
Sun, 21 Feb 2016 10:28:37 +0000 (02:28 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 5 Oct 2016 17:44:27 +0000 (17:44 +0000)
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>
misc/cgo/test/complex.go [new file with mode: 0644]
src/cmd/cgo/gcc.go
src/cmd/cgo/out.go
src/cmd/compile/internal/gc/align.go

diff --git a/misc/cgo/test/complex.go b/misc/cgo/test/complex.go
new file mode 100644 (file)
index 0000000..ca0a97d
--- /dev/null
@@ -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)
+       }
+}
index fc1d01100d2ad1dd7ddddc7c341b8d80fdadb315..9c268ca494d60c1212544125b9addde108988f9d 100644 (file)
@@ -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
                }
 
index 5dfb3a1cd8f9b877847bcd99347d07f33cf04953..50d6b728b759e26d13fafcc7c7e75f8bcee6ee15 100644 (file)
@@ -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.
index 2aae3425d448d28dc9cb2124a3cbab34d170eec6..375870ee805282138ed7f8842ddeacf938ba0068 100644 (file)
@@ -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)