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/compile: internal compiler error when processing invalid recursive type #49276

Closed
rhysh opened this issue Nov 1, 2021 · 6 comments
Closed

cmd/compile: internal compiler error when processing invalid recursive type #49276

rhysh opened this issue Nov 1, 2021 · 6 comments
Labels
NeedsFix
Milestone

Comments

@rhysh
Copy link
Contributor

@rhysh rhysh commented Nov 1, 2021

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

$ go version
go version devel go1.18-02e5913406 Mon Nov 1 22:55:50 2021 +0000 darwin/amd64

Does this issue reproduce with the latest release?

This is new in tip. It is not present in go1.17.2.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/rhys/Library/Caches/go-build"
GOENV="/Users/rhys/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/rhys/go/pkg/mod"
GONOPROXY="*"
GONOSUMDB="*"
GOOS="darwin"
GOPATH="/Users/rhys/go"
GOPRIVATE="*"
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="devel go1.18-02e5913406 Mon Nov 1 22:55:50 2021 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/49/zmds5zsn75z1283vtzxyfr5hj7yjq4/T/go-build3896010661=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

$ cat ./repro.go
package repro

import "unsafe"

type a struct {
	_ [42 - unsafe.Sizeof(a{})]byte
}

$ go install

What did you expect to see?

$ go1.17 version
go version go1.17.2 darwin/amd64

$ go1.17 install
# bug.repro
./repro.go:6:25: invalid composite literal type a

What did you see instead?

$ go version
go version devel go1.18-02e5913406 Mon Nov 1 22:55:50 2021 +0000 darwin/amd64

$ go install
# bug.repro
./repro.go:6:23: internal compiler error: got 0 from types2, but want 42

goroutine 1 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x128300?, 0xc0?}, {0x191cd35, 0x1f}, {0xc000118f18, 0x2, 0x2})
        /usr/local/go/src/cmd/compile/internal/base/print.go:227 +0x1ca
cmd/compile/internal/noder.(*irgen).validateBuiltin(0xc000128300, {0xc000027088, 0x6}, 0xc0000317c0)
        /usr/local/go/src/cmd/compile/internal/noder/validate.go:100 +0x2bf
cmd/compile/internal/noder.(*irgen).validate(0xc000128300, {0x1a76680?, 0xc0000317c0})
        /usr/local/go/src/cmd/compile/internal/noder/validate.go:70 +0x157
cmd/compile/internal/noder.(*irgen).generate.func1({0x1a76680?, 0xc0000317c0?})
        /usr/local/go/src/cmd/compile/internal/noder/irgen.go:297 +0x30
cmd/compile/internal/syntax.Crawl.func1({0x1a76680?, 0xc0000317c0?})
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:41 +0x30
cmd/compile/internal/syntax.inspector.Visit(0xc000060cf0, {0x1a76680?, 0xc0000317c0?})
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:24 +0x31
cmd/compile/internal/syntax.walker.node({{0x1a76300?, 0xc000060cf0?}}, {0x1a76680, 0xc0000317c0?})
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:76 +0x6b
cmd/compile/internal/syntax.walker.node({{0x1a76300?, 0xc000060cf0?}}, {0x1a76a90, 0xc000031780?})
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:179 +0x13ad
cmd/compile/internal/syntax.walker.node({{0x1a76300?, 0xc000060cf0?}}, {0x1a76568, 0xc0003d1080?})
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:192 +0x845
cmd/compile/internal/syntax.walker.node({{0x1a76300?, 0xc000060cf0?}}, {0x1a76838, 0xc0003d10b0?})
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:214 +0xf7d
cmd/compile/internal/syntax.walker.fieldList({{0x1a76300?, 0xc000060cf0?}}, {0xc00000e490, 0x1, 0x1f73840?})
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:360 +0x4b
cmd/compile/internal/syntax.walker.node({{0x1a76300?, 0xc000060cf0?}}, {0x1a76bf8, 0xc000031740?})
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:203 +0x39e
cmd/compile/internal/syntax.walker.node({{0x1a76300?, 0xc000060cf0?}}, {0x1a76c48, 0xc00010bb00?})
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:106 +0x1287
cmd/compile/internal/syntax.walker.declList({{0x1a76300?, 0xc000060cf0?}}, {0xc0003d9de0?, 0x2, 0xc0001196a0?})
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:336 +0x91
cmd/compile/internal/syntax.walker.node({{0x1a76300?, 0xc000060cf0?}}, {0x1a76860, 0xc0003fdcc0?})
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:85 +0xfee
cmd/compile/internal/syntax.Walk(...)
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:57
cmd/compile/internal/syntax.Inspect(...)
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:18
cmd/compile/internal/syntax.Crawl({0x1a76860?, 0xc0003fdcc0?}, 0xc000060ce0?)
        /usr/local/go/src/cmd/compile/internal/syntax/walk.go:40 +0x75
cmd/compile/internal/noder.(*irgen).generate(0xc000128300, {0xc00000e478, 0x1, 0x203000?})
        /usr/local/go/src/cmd/compile/internal/noder/irgen.go:296 +0x2d3
cmd/compile/internal/noder.check2({0xc00000e478, 0x1, 0x1})
        /usr/local/go/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc00001e220, 0x1, 0x0?})
        /usr/local/go/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0x1937480)
        /usr/local/go/src/cmd/compile/internal/gc/main.go:191 +0xb13
main.main()
        /usr/local/go/src/cmd/compile/main.go:55 +0xdd

@ALTree ALTree added the NeedsInvestigation label Nov 2, 2021
@ALTree ALTree added this to the Go1.18 milestone Nov 2, 2021
@danscales
Copy link
Contributor

@danscales danscales commented Nov 2, 2021

cc @griesemer

@griesemer griesemer self-assigned this Nov 2, 2021
@griesemer
Copy link
Contributor

@griesemer griesemer commented Nov 2, 2021

Should be fixed but not a release blocker, and also not urgent. This is pretty pathological code.

@rhysh
Copy link
Contributor Author

@rhysh rhysh commented Nov 2, 2021

Pathological, yes. For context, I ran into this via a typo / copy-paste error. Not urgent, not a blocker, a better error message would be nice.

@griesemer griesemer added NeedsFix and removed NeedsInvestigation labels Nov 4, 2021
@griesemer
Copy link
Contributor

@griesemer griesemer commented Nov 4, 2021

Investigated a bit. The Checker.validType function currently doesn't walk array length expressions and thus doesn't flag the above struct as an invalid type. Separately, the size computation determines the size of the struct eagerly, before it's fully set up. Fixing the first would suffice for this case.

[edit] validType cannot do this check because the array length expression is gone at that point. This cycle should perhaps be detected as part of the type cycle detection mechanism. Not clear why it's not.

@griesemer
Copy link
Contributor

@griesemer griesemer commented Nov 4, 2021

Another fun test case:

package p

import "unsafe"

type a struct { f *[unsafe.Sizeof(a{})]int }

@gopherbot
Copy link

@gopherbot gopherbot commented Nov 5, 2021

Change https://golang.org/cl/361412 mentions this issue: cmd/compile/internal/types2: report error for incomplete struct composite literal type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix
Projects
None yet
Development

No branches or pull requests

5 participants