aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@google.com>2017-01-17 18:09:55 +0100
committerAndrey Konovalov <andreyknvl@google.com>2017-01-18 13:07:53 +0100
commit9d963ea599613fa3c2ebef9e3faaad277bab26a3 (patch)
tree48278d283f3f18934a1b4acc307bd2691ceb91f2
parent41f1d1e486eb7c46f9bd1b084bf87e87a1b8d314 (diff)
prog: fix Size() for unions args
-rw-r--r--prog/prog.go6
-rw-r--r--sys/decl.go4
-rw-r--r--sysgen/sysgen.go2
3 files changed, 8 insertions, 4 deletions
diff --git a/prog/prog.go b/prog/prog.go
index cdc2dfe3c..cd8f43d32 100644
--- a/prog/prog.go
+++ b/prog/prog.go
@@ -116,7 +116,11 @@ func (a *Arg) Size() uintptr {
}
return size
case *sys.UnionType:
- return a.Option.Size()
+ if !typ.Varlen {
+ return typ.Size()
+ } else {
+ return a.Option.Size()
+ }
case *sys.ArrayType:
var size uintptr
for _, in := range a.Inner {
diff --git a/sys/decl.go b/sys/decl.go
index de3554dbf..6c756fa07 100644
--- a/sys/decl.go
+++ b/sys/decl.go
@@ -327,11 +327,11 @@ func (t *StructType) Align() uintptr {
type UnionType struct {
TypeCommon
Options []Type
- varlen bool
+ Varlen bool
}
func (t *UnionType) Size() uintptr {
- if t.varlen {
+ if t.Varlen {
panic("union size is not statically known")
}
size := t.Options[0].Size()
diff --git a/sysgen/sysgen.go b/sysgen/sysgen.go
index 583be5a40..ecc237118 100644
--- a/sysgen/sysgen.go
+++ b/sysgen/sysgen.go
@@ -275,7 +275,7 @@ func generateStructEntry(str Struct, key structKey, out io.Writer) {
}
varlen := ""
if str.Varlen {
- varlen = ", varlen: true"
+ varlen = ", Varlen: true"
}
align := ""
if str.Align != 0 {