aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-09-04 19:53:01 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-09-04 20:25:22 +0200
commit622a1ffd7236529d9774498742810ce1102b009f (patch)
tree10bfbb6ce12f10babff8581a34a0581bd5d0bb4a /pkg
parent291192c61b4d6bad6c11e8732be7de26f1add0ef (diff)
pkg/compiler: prohibit bitfields of size 0
They don't work the way C bitfields work. So this will lead to confusion at least.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/compiler/testdata/errors.txt2
-rw-r--r--pkg/compiler/types.go17
2 files changed, 14 insertions, 5 deletions
diff --git a/pkg/compiler/testdata/errors.txt b/pkg/compiler/testdata/errors.txt
index 512d615c8..c339dcb80 100644
--- a/pkg/compiler/testdata/errors.txt
+++ b/pkg/compiler/testdata/errors.txt
@@ -128,7 +128,7 @@ resource inout[int32] ### resource uses reserved name inout
bar()
s3 {
- f1 int8:0
+ f1 int8:0 ### bitfields of size 0 are not supported
f2 int8:1
f3 int8:7
f4 int8:8
diff --git a/pkg/compiler/types.go b/pkg/compiler/types.go
index 035a47165..29ef4dbf5 100644
--- a/pkg/compiler/types.go
+++ b/pkg/compiler/types.go
@@ -539,10 +539,19 @@ var typeArgBase = namedArg{
Names: []string{"int8", "int16", "int32", "int64", "int16be", "int32be", "int64be", "intptr"},
AllowColon: true,
Check: func(comp *compiler, t *ast.Type) {
- size, _ := comp.parseIntType(t.Ident)
- if t.Value2 > size*8 {
- comp.error(t.Pos2, "bitfield of size %v is too large for base type of size %v",
- t.Value2, size*8)
+ if t.HasColon {
+ if t.Value2 == 0 {
+ // This was not supported historically
+ // and does not work the way C bitfields of size 0 work.
+ // We could allow this, but then we need to make
+ // this work the way C bitfields work.
+ comp.error(t.Pos2, "bitfields of size 0 are not supported")
+ }
+ size, _ := comp.parseIntType(t.Ident)
+ if t.Value2 > size*8 {
+ comp.error(t.Pos2, "bitfield of size %v is too large for base type of size %v",
+ t.Value2, size*8)
+ }
}
},
},