From d2bde102ff975f30067203b5d039174d54a1b701 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 7 Jan 2020 07:27:38 +0100 Subject: pkg/compiler: fix another bitfield layout bug See the added test for details. --- pkg/compiler/gen.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'pkg') 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)) } -- cgit mrf-deployment