From 2cfe62f82077ba012aef55db5288985bc0c426d9 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 5 Jan 2022 20:05:11 +0100 Subject: pkg/compiler: add out_overlay field attribute --- prog/analysis.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'prog/analysis.go') diff --git a/prog/analysis.go b/prog/analysis.go index 697e1eab5..1b572f0c0 100644 --- a/prog/analysis.go +++ b/prog/analysis.go @@ -132,22 +132,29 @@ func foreachArgImpl(arg Arg, ctx *ArgCtx, f func(Arg, *ArgCtx)) { } switch a := arg.(type) { case *GroupArg: + overlayField := 0 if typ, ok := a.Type().(*StructType); ok { ctx.Parent = &a.Inner ctx.Fields = typ.Fields + overlayField = typ.OverlayField } var totalSize uint64 - for _, arg1 := range a.Inner { + for i, arg1 := range a.Inner { + if i == overlayField { + ctx.Offset = ctx0.Offset + } foreachArgImpl(arg1, ctx, f) size := arg1.Size() ctx.Offset += size - totalSize += size + if totalSize < ctx.Offset { + totalSize = ctx.Offset - ctx0.Offset + } } claimedSize := a.Size() varlen := a.Type().Varlen() if varlen && totalSize > claimedSize || !varlen && totalSize != claimedSize { panic(fmt.Sprintf("bad group arg size %v, should be <= %v for %#v type %#v", - totalSize, claimedSize, a, a.Type())) + totalSize, claimedSize, a, a.Type().Name())) } case *PointerArg: if a.Res != nil { -- cgit mrf-deployment