pkg/compiler: fix alignment calculation bug

This commit is contained in:
Dmitry Vyukov 2017-09-04 20:54:29 +02:00
parent 1c0d4caf7c
commit a29e1be6ff

View File

@ -276,9 +276,7 @@ func (comp *compiler) addAlignment(fields []sys.Type, varlen, packed bool, align
}
return newFields
}
var off uint64
// TODO(dvyukov): this is wrong: if alignAttr!=0, we must use it, not max
align := alignAttr
var align, off uint64
for i, f := range fields {
if i > 0 && !fields[i-1].BitfieldMiddle() {
a := comp.typeAlign(f)
@ -300,6 +298,9 @@ func (comp *compiler) addAlignment(fields []sys.Type, varlen, packed bool, align
off += f.Size()
}
}
if alignAttr != 0 {
align = alignAttr
}
if align != 0 && off%align != 0 && !varlen {
pad := align - off%align
off += pad