cmd/cgo: fix default alignment for empty structs

Fixes #5242.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/125120043
This commit is contained in:
Matthew Dempsky 2014-08-11 22:10:17 -07:00 committed by Ian Lance Taylor
parent 03e6a88ef0
commit 31a996edb6
3 changed files with 35 additions and 0 deletions

View file

@ -1534,6 +1534,9 @@ func (c *typeConv) pad(fld []*ast.Field, size int64) []*ast.Field {
// Struct conversion: return Go and (6g) C syntax for type.
func (c *typeConv) Struct(dt *dwarf.StructType, pos token.Pos) (expr *ast.StructType, csyntax string, align int64) {
// Minimum alignment for a struct is 1 byte.
align = 1
var buf bytes.Buffer
buf.WriteString("struct {")
fld := make([]*ast.Field, 0, 2*len(dt.Field)+1) // enough for padding around every field