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

Closed
qmuntal opened this issue Jan 20, 2022 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@qmuntal
Copy link
Contributor

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

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

@heschi
Copy link
Contributor

heschi commented Jan 20, 2022

cc @ianlancetaylor

@heschi heschi added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 20, 2022
@heschi heschi added this to the Go1.19 milestone Jan 20, 2022
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 25, 2022
jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
Fixes golang#50710

Change-Id: I62feddbe3eaae9605d196bec60d378614436603a
Reviewed-on: https://go-review.googlesource.com/c/go/+/379754
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
@golang golang locked and limited conversation to collaborators Jun 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

No branches or pull requests

4 participants