Skip to content

cmd/cgo: Invalid code generation when using go 1.15 #40126

Closed
@abdelrahman-t

Description

@abdelrahman-t

What version of Go are you using (go version)?

$ go version > go version go1.15beta1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env >

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/user/golib/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user/golib:/home/user/Desktop/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build080754714=/tmp/go-build -gno-record-gcc-switches"

What did you do?

// tuntap_c.go
// Author: @danderson https://code.google.com/archive/p/tuntap/
package tuntap

/*
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/if_tun.h>

#define IFREQ_SIZE sizeof(struct ifreq)
*/
import "C"

const (
	flagTruncated = C.TUN_PKT_STRIP

	iffTun      = C.IFF_TUN
	iffTap      = C.IFF_TAP
	iffnopi     = C.IFF_NO_PI
	iffOneQueue = C.IFF_ONE_QUEUE
)

type ifReq struct {
	Name  [C.IFNAMSIZ]byte
	Flags uint16
	pad   [C.IFREQ_SIZE - C.IFNAMSIZ - 2]byte
}

What did you expect to see?

// tuntap.go
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs=true src/tuntap_c.go
// ...
type ifReq struct {
	Name  [0x10]byte
	Flags uint16
	pad   [0x28 - 0x10 - 2]byte
}

This works as expected when using go 1.14

What did you see instead?

// tuntap.go
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs=true src/tuntap_c.go
// ...
type ifReq struct {
	Name  [0x10]byte
	Flags uint16
	pad   [uint64 - 0x10 - 2]byte // compiler: uint64 (type) is not an expression
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions