Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: exported function name shadowing issue #44974

Open
pmuetschard opened this issue Mar 12, 2021 · 2 comments
Open

cmd/cgo: exported function name shadowing issue #44974

pmuetschard opened this issue Mar 12, 2021 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@pmuetschard
Copy link

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

$ go version
go version go1.16.2 linux/amd64

Does this issue reproduce with the latest release?

Yes, this was introduced somewhere between 1.14 and 1.16.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xxx/.cache/go-build"
GOENV="/home/xxx/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/xxx/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/xxx/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/xxx/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/xxx/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build2817633273=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Attempting to compile the following snippet fails in 1.16:

package baz

// typedef struct { int x; } foo;
import "C"

//export bar
func bar(foo *C.foo) {
}
$ /xxx/go1.14/bin/go build foo.go 
$ /xxx/go1.16.2/bin/go build foo.go 
# command-line-arguments
_cgo_export.c: In function ‘bar’:
_cgo_export.c:28:3: error: expected specifier-qualifier-list before ‘foo’
   28 |   foo* p0;
      |   ^~~
_cgo_export.c:32:8: error: ‘_cgo_argtype’ {aka ‘struct <anonymous>’} has no member named ‘p0’
   32 |  _cgo_a.p0 = foo;
      |        ^

The generated C code fails to compile, because of the overloaded foo name (variable shadowing the type):

void bar(foo* foo) {
        typedef struct {
                foo* p0; // <---- fails here
        } __attribute__((__packed__, __gcc_struct__)) _cgo_argtype;
}

With 1.14, the generated code doesn't use the name from the go code, and so doesn't have this issue:

void bar(foo* p0) {
	struct {
		foo* p0;
	} __attribute__((__packed__, __gcc_struct__)) a;

What did you expect to see?

No build failure.

What did you see instead?

Build failure.

@dmitshur dmitshur changed the title cgo exported function name shadowing issue cmd/cgo: exported function name shadowing issue Mar 12, 2021
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 12, 2021
@dmitshur
Copy link
Contributor

CC @ianlancetaylor.

@dmitshur dmitshur added this to the Backlog milestone Mar 12, 2021
@ianlancetaylor
Copy link
Contributor

ianlancetaylor commented Mar 15, 2021

This was broken by https://golang.org/cl/222619. I don't see an obvious path forward other than reverting that change.

CC @nathan-fiscaletti

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Triage Backlog
Development

No branches or pull requests

4 participants