Skip to content

Commit bfa7a55

Browse files
cmd/cgo: for C bitfields use only valid Go integer types
Fixes #22958 Change-Id: Ib078a5f6e1105a2afca77c6d9a05f65ddf5d9010 Reviewed-on: https://go-review.googlesource.com/81435 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent ea0d2c1 commit bfa7a55

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

misc/cgo/test/issue22958.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package cgotest
6+
7+
// Test handling of bitfields.
8+
9+
/*
10+
typedef struct {
11+
unsigned long long f8 : 8;
12+
unsigned long long f16 : 16;
13+
unsigned long long f24 : 24;
14+
unsigned long long f32 : 32;
15+
unsigned long long f40 : 40;
16+
unsigned long long f48 : 48;
17+
unsigned long long f56 : 56;
18+
unsigned long long f64 : 64;
19+
} issue22958Type;
20+
*/
21+
import "C"
22+
23+
// Nothing to run, just make sure this compiles.
24+
var Vissue22958 C.issue22958Type

src/cmd/cgo/gcc.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2388,7 +2388,9 @@ func (c *typeConv) Struct(dt *dwarf.StructType, pos token.Pos) (expr *ast.Struct
23882388
size := t.Size
23892389
talign := t.Align
23902390
if f.BitSize > 0 {
2391-
if f.BitSize%8 != 0 {
2391+
switch f.BitSize {
2392+
case 8, 16, 32, 64:
2393+
default:
23922394
continue
23932395
}
23942396
size = f.BitSize / 8

0 commit comments

Comments
 (0)