Skip to content

cmd/cgo: type confusion between CGO and CoreFoundation types on Go1.10 #24161

@akalin-keybase

Description

@akalin-keybase

Please answer these questions before submitting your issue. Thanks!

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

1.10

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/akalin-keybase/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/akalin-keybase/go"
GORACE=""
GOROOT="/Users/akalin-keybase/homebrew/Cellar/go/1.10/libexec"
GOTMPDIR=""
GOTOOLDIR="/Users/akalin-keybase/homebrew/Cellar/go/1.10/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/f7/k3hkmgcx71d2n0vz0fp2662r0000gq/T/go-build917425438=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

The following file should compile:

// +build darwin

package kext

/*
#cgo LDFLAGS: -framework CoreFoundation -framework IOKit

#include <CoreFoundation/CoreFoundation.h>
*/
import "C"

func bugRepro() {
	arr := returnsCFArrayRef()
	// If arr is replaced with C.CFArrayRef(arr), compilation succeeds.
	C.CFArrayCreateCopy(nil, arr)
}

returnsCFArrayRef is a function in another file in the same package that looks like

func returnsCFArrayRef() C.CFArrayRef {
  // returns C.CFArrayRef(0) or C.CFArrayRef(nil) depending on go version.
}

A full example is on https://gist.github.com/akalin-keybase/6d075a61e683a4b2e2424638308e95c5 .

What did you see instead?

go install ./...
# github.com/keybase/go-kext
./file2.go:22: cannot use arr (type _Ctype_CFArrayRef) as type *_Ctype_struct___CFArray in argument to func literal

Compilation succeeds with go 1.9.2.

This is likely related to the go 1.10 changes that made some C types map to uintptr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions