aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler/gen.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-03-02 15:44:54 +0100
committerDmitry Vyukov <dvyukov@google.com>2018-03-05 12:10:27 +0100
commit5ef8dbdf5a63ccf7e069527dbb2493dc2ef0c319 (patch)
tree25f38d85ac74951764770ed777033ee8ed9ac542 /pkg/compiler/gen.go
parenta339951e5f3c045290340330bcea3ff4155b8334 (diff)
pkg/compiler: support size attribute for unions
Diffstat (limited to 'pkg/compiler/gen.go')
-rw-r--r--pkg/compiler/gen.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/pkg/compiler/gen.go b/pkg/compiler/gen.go
index 74d1b5d78..5bf239e79 100644
--- a/pkg/compiler/gen.go
+++ b/pkg/compiler/gen.go
@@ -165,14 +165,24 @@ func (comp *compiler) genStructDescs(syscalls []*prog.Syscall) []*prog.KeyedStru
if !checkStruct(t.Key, &t.StructDesc) {
return
}
+ structNode := comp.structNodes[t.StructDesc]
+ varlen, sizeAttr := comp.parseUnionAttrs(structNode)
t.TypeSize = 0
- varlen := comp.parseUnionAttrs(comp.structNodes[t.StructDesc])
if !varlen {
for _, fld := range t.Fields {
- if t.TypeSize < fld.Size() {
- t.TypeSize = fld.Size()
+ sz := fld.Size()
+ if sizeAttr != sizeUnassigned && sz > sizeAttr {
+ comp.error(structNode.Pos, "union %v has size attribute %v"+
+ " which is less than field %v size %v",
+ structNode.Name.Name, sizeAttr, fld.Name(), sz)
+ }
+ if t.TypeSize < sz {
+ t.TypeSize = sz
}
}
+ if sizeAttr != sizeUnassigned {
+ t.TypeSize = sizeAttr
+ }
}
}
}