aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-01-07 07:27:38 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-01-07 10:02:09 +0100
commitd2bde102ff975f30067203b5d039174d54a1b701 (patch)
treeb4f560eee64690a6acc58c46736e80f7dbddb77a /pkg
parentc43471c3ac1d6cccf644d4ea3f696f3820ade17b (diff)
pkg/compiler: fix another bitfield layout bug
See the added test for details.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/compiler/gen.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/pkg/compiler/gen.go b/pkg/compiler/gen.go
index 03c0f2b0b..8a974c7ba 100644
--- a/pkg/compiler/gen.go
+++ b/pkg/compiler/gen.go
@@ -299,6 +299,16 @@ func (comp *compiler) layoutStruct(t *prog.StructType, varlen, packed bool) {
byteOffset += pad
if i != 0 && t.Fields[i-1].IsBitfield() {
setBitfieldTypeSize(t.Fields[i-1], pad)
+ if bitOffset >= 8*pad {
+ // The padding is due to bitfields, so consume the bitOffset.
+ bitOffset -= 8 * pad
+ } else if bitOffset >= 8 {
+ // Unclear is this is a bug or not and what to do in this case.
+ // But since we don't have any descriptions that trigger this,
+ // let's just guard with the panic.
+ panic(fmt.Sprintf("bad bitOffset: %v.%v pad=%v bitOffset=%v",
+ t.Name(), f.FieldName(), pad, bitOffset))
+ }
} else {
newFields = append(newFields, genPad(pad))
}