aboutsummaryrefslogtreecommitdiff
path: root/src/lib/reflect
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-04-29 18:51:12 -0700
committerRob Pike <r@golang.org>2009-04-29 18:51:12 -0700
commitc0b8b969ae353f48445a18ea9e856f1997fba270 (patch)
tree0d016b64ff00312e40bbbd9d203d780db5088b99 /src/lib/reflect
parent49eb63cfd51212d177330eb1f44ec42efa6b62b6 (diff)
downloadgo-c0b8b969ae353f48445a18ea9e856f1997fba270.tar.xz
Bug in reflect found by gri. Structs in 6g have a minimum alignment.
iant: will this be ok in gccgo? R=rsc DELTA=9 (8 added, 0 deleted, 1 changed) OCL=28059 CL=28062
Diffstat (limited to 'src/lib/reflect')
-rw-r--r--src/lib/reflect/type.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/lib/reflect/type.go b/src/lib/reflect/type.go
index 107fd78779..b073afc22e 100644
--- a/src/lib/reflect/type.go
+++ b/src/lib/reflect/type.go
@@ -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,