Skip to content

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

Closed
@rhysh

Description

@rhysh

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

Activity

added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Nov 2, 2021
added this to the Go1.18 milestone on Nov 2, 2021
danscales

danscales commented on Nov 2, 2021

@danscales
Contributor
self-assigned this
on Nov 2, 2021
griesemer

griesemer commented on Nov 2, 2021

@griesemer
Contributor

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

rhysh

rhysh commented on Nov 2, 2021

@rhysh
ContributorAuthor

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.

added
NeedsFixThe path to resolution is known, but the work has not been done.
and removed
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Nov 4, 2021
griesemer

griesemer commented on Nov 4, 2021

@griesemer
Contributor

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

griesemer commented on Nov 4, 2021

@griesemer
Contributor

Another fun test case:

package p

import "unsafe"

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

gopherbot commented on Nov 5, 2021

@gopherbot
Contributor

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

locked and limited conversation to collaborators on Jun 23, 2023
added a commit that references this issue on Sep 19, 2024
61d789d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @rhysh@danscales@ALTree@griesemer@gopherbot

        Issue actions

          cmd/compile: internal compiler error when processing invalid recursive type · Issue #49276 · golang/go