]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: for C bitfields use only valid Go integer types
authorIan Lance Taylor <iant@golang.org>
Fri, 1 Dec 2017 14:57:37 +0000 (06:57 -0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 1 Dec 2017 23:50:23 +0000 (23:50 +0000)
Fixes #22958

Change-Id: Ib078a5f6e1105a2afca77c6d9a05f65ddf5d9010
Reviewed-on: https://go-review.googlesource.com/81435
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
misc/cgo/test/issue22958.go [new file with mode: 0644]
src/cmd/cgo/gcc.go

diff --git a/misc/cgo/test/issue22958.go b/misc/cgo/test/issue22958.go
new file mode 100644 (file)
index 0000000..a5f058f
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cgotest
+
+// Test handling of bitfields.
+
+/*
+typedef struct {
+       unsigned long long f8  : 8;
+       unsigned long long f16 : 16;
+       unsigned long long f24 : 24;
+       unsigned long long f32 : 32;
+       unsigned long long f40 : 40;
+       unsigned long long f48 : 48;
+       unsigned long long f56 : 56;
+       unsigned long long f64 : 64;
+} issue22958Type;
+*/
+import "C"
+
+// Nothing to run, just make sure this compiles.
+var Vissue22958 C.issue22958Type
index a59892ef0082a263aa5c3c7732deb08fdfd4c649..5cd6ac953c39935f1c17e0e83c92f10c178d56c7 100644 (file)
@@ -2388,7 +2388,9 @@ func (c *typeConv) Struct(dt *dwarf.StructType, pos token.Pos) (expr *ast.Struct
                size := t.Size
                talign := t.Align
                if f.BitSize > 0 {
-                       if f.BitSize%8 != 0 {
+                       switch f.BitSize {
+                       case 8, 16, 32, 64:
+                       default:
                                continue
                        }
                        size = f.BitSize / 8