]> Cypherpunks repositories - gostls13.git/commitdiff
Bug in reflect found by gri. Structs in 6g have a minimum alignment.
authorRob Pike <r@golang.org>
Thu, 30 Apr 2009 01:51:12 +0000 (18:51 -0700)
committerRob Pike <r@golang.org>
Thu, 30 Apr 2009 01:51:12 +0000 (18:51 -0700)
iant: will this be ok in gccgo?

R=rsc
DELTA=9  (8 added, 0 deleted, 1 changed)
OCL=28059
CL=28062

src/lib/reflect/type.go

index 107fd78779452721b0a28f515182fe9ad7ba6875..b073afc22efdb08807705cb54fa886a38fe981c5 100644 (file)
@@ -80,9 +80,13 @@ type allTypes struct {
        xuintptr        uintptr;
 }
 
-var x allTypes
+var (
+       x allTypes;
+       minStruct struct { uint8 };
+)
 
 const (
+       minStructAlign = unsafe.Sizeof(minStruct) - 1;
        ptrsize = unsafe.Sizeof(&x);
        interfacesize = unsafe.Sizeof(x.xinterface);
 )
@@ -394,6 +398,10 @@ func (t *structTypeStruct) Size() int {
                size += elemsize;
        }
        if (structalign > 0) {
+               // 6g etc. always aligns structs to a minimum size, typically int64
+               if structalign < minStructAlign {
+                       structalign = minStructAlign
+               }
                // TODO: In the PPC64 ELF ABI, floating point fields
                // in a struct are aligned to a 4-byte boundary, but
                // if the first field in the struct is a 64-bit float,