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

go/internal/gccgoimporter: fails to parse pointer loop with embedded field #34182

Closed
matszpk opened this issue Sep 9, 2019 · 11 comments
Closed

go/internal/gccgoimporter: fails to parse pointer loop with embedded field #34182

matszpk opened this issue Sep 9, 2019 · 11 comments
Labels
FrozenDueToAge NeedsInvestigation
Milestone

Comments

@matszpk
Copy link

@matszpk matszpk commented Sep 9, 2019

I am using go 1.12.2 on Arch Linux (gcc 9.1.0) updated from 2019.09.08.
I am using AMD Ryzen (first generation processor).
Any trial of testing any package with import "go.mongodb.org/mongo-driver" causes enough strange error:

`#go.mongodb.org/mongo-driver/bson
panic: import error :1:31 (byte offset = 30): anonymous field expected [recovered]
panic: import error :1:31 (byte offset = 30): anonymous field expected

goroutine 1 [running]:
types.r
/build/gcc/src/gcc/libgo/go/go/types/check.go:240
go..z2ftypes.Checker.handleBailout
/build/gcc/src/gcc/libgo/go/go/types/check.go:233
panic
/build/gcc/src/gcc/libgo/go/runtime/panic.go:555
go..z2finternal..z2fgccgoimporter.parser.error
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:86
go..z2finternal..z2fgccgoimporter.parser.parseField
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:251
go..z2finternal..z2fgccgoimporter.parser.parseStructType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:662
go..z2finternal..z2fgccgoimporter.parser.parseTypeSpec
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:802
go..z2finternal..z2fgccgoimporter.parser.parseSavedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:1022
go..z2finternal..z2fgccgoimporter.parser.parseTypeAfterAngle
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:891
go..z2finternal..z2fgccgoimporter.parser.parseType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:879
go..z2finternal..z2fgccgoimporter.parser.parseNamedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:526
go..z2finternal..z2fgccgoimporter.parser.parseTypeSpec
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:791
go..z2finternal..z2fgccgoimporter.parser.parseSavedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:1022
go..z2finternal..z2fgccgoimporter.parser.parseTypeAfterAngle
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:891
go..z2finternal..z2fgccgoimporter.parser.parseType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:879
go..z2finternal..z2fgccgoimporter.parser.parseParam
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:278
go..z2finternal..z2fgccgoimporter.parser.parseParamList
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:683
go..z2finternal..z2fgccgoimporter.parser.parseFunctionType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:721
go..z2finternal..z2fgccgoimporter.parser.parseFunc
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:737
go..z2finternal..z2fgccgoimporter.parser.parseInterfaceType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:758
go..z2finternal..z2fgccgoimporter.parser.parseTypeSpec
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:805
go..z2finternal..z2fgccgoimporter.parser.parseSavedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:1022
go..z2finternal..z2fgccgoimporter.parser.parseTypeAfterAngle
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:891
go..z2finternal..z2fgccgoimporter.parser.parseType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:879
go..z2finternal..z2fgccgoimporter.parser.parseNamedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:526
go..z2finternal..z2fgccgoimporter.parser.parseTypeSpec
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:791
go..z2finternal..z2fgccgoimporter.parser.parseSavedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:1022
go..z2finternal..z2fgccgoimporter.parser.parseTypeAfterAngle
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:891
go..z2finternal..z2fgccgoimporter.parser.parseType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:879
go..z2finternal..z2fgccgoimporter.parser.parseMapType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:617
go..z2finternal..z2fgccgoimporter.parser.parseTypeSpec
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:796
go..z2finternal..z2fgccgoimporter.parser.parseSavedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:1022
go..z2finternal..z2fgccgoimporter.parser.parseTypeAfterAngle
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:891
go..z2finternal..z2fgccgoimporter.parser.parseType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:879
go..z2finternal..z2fgccgoimporter.parser.parseField
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:241
go..z2finternal..z2fgccgoimporter.parser.parseStructType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:662
go..z2finternal..z2fgccgoimporter.parser.parseTypeSpec
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:802
go..z2finternal..z2fgccgoimporter.parser.parseSavedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:1022
go..z2finternal..z2fgccgoimporter.parser.parseTypeAfterAngle
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:891
go..z2finternal..z2fgccgoimporter.parser.parseType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:879
go..z2finternal..z2fgccgoimporter.parser.parseNamedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:526
go..z2finternal..z2fgccgoimporter.parser.parseTypeSpec
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:791
go..z2finternal..z2fgccgoimporter.parser.parseSavedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:1022
go..z2finternal..z2fgccgoimporter.parser.parseTypeAfterAngle
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:891
go..z2finternal..z2fgccgoimporter.parser.parseType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:879
go..z2finternal..z2fgccgoimporter.parser.parsePointerType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:782
go..z2finternal..z2fgccgoimporter.parser.parseTypeSpec
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:809
go..z2finternal..z2fgccgoimporter.parser.parseSavedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:1022
go..z2finternal..z2fgccgoimporter.parser.parseTypeAfterAngle
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:891
go..z2finternal..z2fgccgoimporter.parser.parseType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:879
go..z2finternal..z2fgccgoimporter.parser.parseField
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:241
go..z2finternal..z2fgccgoimporter.parser.parseStructType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:662
go..z2finternal..z2fgccgoimporter.parser.parseTypeSpec
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:802
go..z2finternal..z2fgccgoimporter.parser.parseSavedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:1022
go..z2finternal..z2fgccgoimporter.parser.parseTypeAfterAngle
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:891
go..z2finternal..z2fgccgoimporter.parser.parseType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:879
go..z2finternal..z2fgccgoimporter.parser.parseNamedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:526
go..z2finternal..z2fgccgoimporter.parser.parseTypeSpec
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:791
go..z2finternal..z2fgccgoimporter.parser.parseSavedType
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:1022
go..z2finternal..z2fgccgoimporter.parser.parseTypes
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:998
go..z2finternal..z2fgccgoimporter.parser.parseDirective
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:1175
go..z2finternal..z2fgccgoimporter.parser.parsePackage
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/parser.go:1211
gccgoimporter.GetImporter..func1
/build/gcc/src/gcc/libgo/go/go/internal/gccgoimporter/importer.go:216
go..z2fimporter.gccgoimports.ImportFrom
/build/gcc/src/gcc/libgo/go/go/importer/importer.go:128
go..z2fimporter.gccgoimports.Import
/build/gcc/src/gcc/libgo/go/go/importer/importer.go:121
go..z2ftypes.Checker.importPackage
/build/gcc/src/gcc/libgo/go/go/types/resolver.go:161
go..z2ftypes.Checker.collectObjects
/build/gcc/src/gcc/libgo/go/go/types/resolver.go:256
go..z2ftypes.Checker.checkFiles
/build/gcc/src/gcc/libgo/go/go/types/check.go:252
go..z2ftypes.Checker.Files
/build/gcc/src/gcc/libgo/go/go/types/check.go:245
go..z2ftypes.Config.Check
/build/gcc/src/gcc/libgo/go/go/types/api.go:351
main.main
:0`

go env output:

GOARCH="amd64"
GOBIN=""
GOCACHE="/mnt/oldsys/home/mat/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mat/go"
GOPROXY=""
GORACE=""
GOROOT="/usr"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0"
GCCGO="/usr/bin/gccgo"
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-build001405097=/tmp/go-build -gno-record-gcc-switches -funwind-tables"

Maybe this is bug in gcimporter or other internals? I don't know.

@agnivade
Copy link
Contributor

@agnivade agnivade commented Sep 9, 2019

This sounds like an issue with the code itself. Have you tried raising an issue with mongodb ?

Also, this sounds like easily reproducible. Can you provide us with a small self-contained reproducer which demonstrates the issue ? Thanks.

@matszpk
Copy link
Author

@matszpk matszpk commented Sep 9, 2019

Yes. I did. In package is workspace with trivial example.
mongodb-tests-ws.zip

@matszpk
Copy link
Author

@matszpk matszpk commented Sep 9, 2019

I am using gccgo compiler, because only that compiler is available in standard installation from Arch Linux (I am using go from Arch standard package).

@matszpk
Copy link
Author

@matszpk matszpk commented Sep 9, 2019

I was trying run test on my old 32-bit system (Athlon XP with gentoo) with using builtin gccgo (9.1.0) and I got this same error.

@agnivade
Copy link
Contributor

@agnivade agnivade commented Sep 9, 2019

Oh I see you are using gccgo, sorry I missed that. Is it a requirement that you use gccgo ? Because you can easily install the standard Go distribution in your machine.

@agnivade agnivade changed the title While trying to test any package with "mongodb" imports go causes "anonymous field expected" panics. gccgo: While trying to test any package with "mongodb" imports go causes "anonymous field expected" panics. Sep 9, 2019
@gopherbot gopherbot added this to the Gccgo milestone Sep 9, 2019
@agnivade agnivade added the NeedsInvestigation label Sep 9, 2019
@OneOfOne
Copy link
Contributor

@OneOfOne OneOfOne commented Sep 9, 2019

Off topic, but standard go is available in the community repo.

┏━ oneofone@voyager ❰~❱
┗━❰1❱━● sudo pacman -S go
warning: go-2:1.13-1 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...
Package (1)   Old Version  New Version  Net Change
community/go  2:1.13-1     2:1.13-1       0.00 MiB

@ianlancetaylor ianlancetaylor changed the title gccgo: While trying to test any package with "mongodb" imports go causes "anonymous field expected" panics. go/internal/gccgoimporter: fails to parse pointer loop Sep 10, 2019
@ianlancetaylor ianlancetaylor changed the title go/internal/gccgoimporter: fails to parse pointer loop go/internal/gccgoimporter: fails to parse pointer loop with embedded field Sep 10, 2019
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Sep 10, 2019

This is a bug in go/internal/gccgoimporter. A simple test case is

package issue34182

type T1 struct {
	f *T2
}

type T2 struct {
	f map[int] T3
}

type T3 interface {
	M(T4)
}

type T4 struct {
	*T2
}

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Sep 10, 2019

Slightly simpler still:

package issue34182

type T1 struct {
	f *T2
}

type T2 struct {
	f T3
}

type T3 struct {
	*T2
}

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 10, 2019

Change https://golang.org/cl/194440 mentions this issue: go/internal/gccgoimporter: support embedded field in pointer loop

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 10, 2019

Change https://golang.org/cl/194562 mentions this issue: go/internal/gccgoimporter: support embedded field in pointer loop

gopherbot pushed a commit to golang/gofrontend that referenced this issue Sep 10, 2019
Backport of https://golang.org/cl/194440.  Original description:

    If an embedded field refers to a type via a pointer, the parser needs
    to know the name of the embedded field. It is possible that the
    pointer type is not yet resolved. This CL fixes the parser to handle
    that case by setting the pointer element type to the unresolved named
    type while the pointer is being resolved.

Updates golang/go#34182

Change-Id: Id95261b3bd073c3ab18b221c697036c5339572f0
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/194562
Reviewed-by: Cherry Zhang <cherryyz@google.com>
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Sep 10, 2019

Thanks for the report. This has been fixed on GCC trunk and GCC 9 branch.

It is likely that you can work around the problem by running go test -vet=off.

kraj pushed a commit to kraj/gcc that referenced this issue Sep 10, 2019
    
    Backport of https://golang.org/cl/194440.  Original description:
    
        If an embedded field refers to a type via a pointer, the parser needs
        to know the name of the embedded field. It is possible that the
        pointer type is not yet resolved. This CL fixes the parser to handle
        that case by setting the pointer element type to the unresolved named
        type while the pointer is being resolved.
    
    Updates golang/go#34182
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/194562


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-9-branch@275607 138bc75d-0d04-0410-961f-82ee72b054a4
kraj pushed a commit to kraj/gcc that referenced this issue Sep 10, 2019
    
    Backport of https://golang.org/cl/194440.  Original description:
    
        If an embedded field refers to a type via a pointer, the parser needs
        to know the name of the embedded field. It is possible that the
        pointer type is not yet resolved. This CL fixes the parser to handle
        that case by setting the pointer element type to the unresolved named
        type while the pointer is being resolved.
    
    Updates golang/go#34182
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/194562


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@275606 138bc75d-0d04-0410-961f-82ee72b054a4
kraj pushed a commit to kraj/gcc that referenced this issue Jan 11, 2020
    
    Backport of https://golang.org/cl/194440.  Original description:
    
        If an embedded field refers to a type via a pointer, the parser needs
        to know the name of the embedded field. It is possible that the
        pointer type is not yet resolved. This CL fixes the parser to handle
        that case by setting the pointer element type to the unresolved named
        type while the pointer is being resolved.
    
    Updates golang/go#34182
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/194562

From-SVN: r275607
@golang golang locked and limited conversation to collaborators Sep 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

5 participants