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/go: reports errors for a correct preamble when it contains a builtin C type and a C.* name can't be resolved #50710

Open
qmuntal opened this issue Jan 20, 2022 · 2 comments
Labels
NeedsInvestigation
Milestone

Comments

@qmuntal
Copy link
Contributor

@qmuntal qmuntal commented Jan 20, 2022

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

go version go1.17.2 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\qmuntaldiaz\AppData\Local\go-build
set GOENV=C:\Users\qmuntaldiaz\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\qmuntaldiaz\go\pkg\mod
set GONOPROXY=github.com/microsoft/*
set GONOSUMDB=github.com/microsoft/*
set GOOS=windows
set GOPATH=C:\Users\qmuntaldiaz\go
set GOPRIVATE=github.com/microsoft/*
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.2
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\qmuntaldiaz\code\gotest\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\QMUNTA~1\AppData\Local\Temp\go-build2404042358=/tmp/go-build -gno-record-gcc-switches

What did you do?

==foo.go==

package foo

// int StrLen(_GoString_ s) {
//	return _GoStringLen(s);
// }
import "C"
import "fmt"

func Test() {
	fmt.Println(C.StrLen1("goo"))
}

go tool cgo foo.go

What did you expect to see?

Only this error message:

foo.go:10:14: could not determine kind of name for C.StrLen1

What did you see instead?

I saw the previous error and a preamble error, when the preamble is perfectly fine.

foo.go:10:14: could not determine kind of name for C.StrLen1
cgo: 
gcc errors for preamble:
foo.go:3:13: error: unknown type name '_GoString_'
    3 | // int StrLen(_GoString_ s) {
      |             ^~~~~~~~~~

_GoString_ is defined in the buildin prolog but we are not adding the prolog to the preamble when checking if the preamble has any error:

go/src/cmd/cgo/gcc.go

Lines 492 to 495 in e7d5857

preambleErrors := p.gccErrors([]byte(f.Preamble))
if len(preambleErrors) > 0 {
error_(token.NoPos, "\n%s errors for preamble:\n%s", gccBaseCmd[0], preambleErrors)
}

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 20, 2022

Change https://golang.org/cl/379754 mentions this issue: cmd/go: prepend builtin prolog when checking for preamble errors

@heschi
Copy link
Contributor

@heschi heschi commented Jan 20, 2022

@heschi heschi added the NeedsInvestigation label Jan 20, 2022
@heschi heschi added this to the Go1.19 milestone Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

3 participants