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: SIGSEGV in noder.checkFetchBody #49246

Closed
cloneable opened this issue Oct 31, 2021 · 1 comment
Closed

cmd/compile: SIGSEGV in noder.checkFetchBody #49246

cloneable opened this issue Oct 31, 2021 · 1 comment
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@cloneable
Copy link

cloneable commented Oct 31, 2021

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

$ go version
go version devel go1.18-8e3d5f0bb3 Sun Oct 31 08:29:02 2021 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Code uses generics, so can't build with 1.17.

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="[HOME]/Library/Caches/go-build"
GOENV="[HOME]/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="[HOME]/.go/pkg/mod"
GONOPROXY="github.com/cloneable/*"
GONOSUMDB="github.com/cloneable/*"
GOOS="darwin"
GOPATH="[HOME]/.go"
GOPRIVATE="github.com/cloneable/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="[HOME]/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="[HOME]/sdk/gotip/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="devel go1.18-8e3d5f0bb3 Sun Oct 31 08:29:02 2021 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="[REPO]/go.mod"
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=[TMPDIR]=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Building a package with go build . after I moved some generic types and functions into a separate package. No functional change, pure refactor.

package a

import "b"

func Crash() { b.Y(b.X)() }
package b

type R[T any] struct{ v T }

func (r R[T]) Self() R[T] { return R[T]{} }

type Fn[T any] func() R[T]

func X() (r R[int]) { return r.Self() }

func Y[T any](a Fn[T]) Fn[int] {
	return func() (r R[int]) {
		// No crash: return R[int]{}
		return r.Self()
	}
}

Changing Y's return type to Fn[T] (and returning func() (r R[T]) also prevents a crash.

What did you expect to see?

The package compile fine as it did just minutes before.

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x17df9dc]

goroutine 1 [running]:
cmd/compile/internal/noder.checkFetchBody(0x7850510?)
        [HOME]/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:626 +0x1c
cmd/compile/internal/noder.(*genInst).getInstantiation(0x1f739c0, 0xc00045c340, {0xc0000f2278, 0x1, 0x1a7c538?}, 0x93?)
        [HOME]/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:641 +0x53
cmd/compile/internal/noder.(*genInst).scanForGenCalls.func1({0x1a7af58, 0xc0000b7b90?})
        [HOME]/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:169 +0x2df
cmd/compile/internal/ir.Visit.func1({0x1a7af58, 0xc0000b7b90})
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/visit.go:105 +0x30
cmd/compile/internal/ir.doNodes(...)
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1512
cmd/compile/internal/ir.(*ReturnStmt).doChildren(0x1a7cab0?, 0xc0004e16e0)
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1049 +0x8c
cmd/compile/internal/ir.DoChildren(...)
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a7cab0, 0xc0004b19a0})
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.doNodes(...)
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1512
cmd/compile/internal/ir.(*IfStmt).doChildren(0xc0004b7ea0, 0xc0004e16e0)
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:641 +0x145
cmd/compile/internal/ir.DoChildren(...)
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a7bbd8, 0xc0004b7ea0})
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.doNodes(...)
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1512
cmd/compile/internal/ir.(*Func).doChildren(0x1a7b8b8?, 0xc0004e16e0?)
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/func.go:152 +0x6e
cmd/compile/internal/ir.DoChildren(...)
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a7b8b8, 0xc0003fdce0})
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.Visit({0x1a7b8b8, 0xc0003fdce0}, 0xc0004fa300)
        [HOME]/sdk/gotip/src/cmd/compile/internal/ir/visit.go:108 +0xb8
cmd/compile/internal/noder.(*genInst).scanForGenCalls(0x1f739c0, {0x1a7b8b8, 0xc0003fdce0})
        [HOME]/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:151 +0x1f0
cmd/compile/internal/noder.(*genInst).buildInstantiations(0x1f739c0, 0x1)
        [HOME]/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:73 +0x85
cmd/compile/internal/noder.BuildInstantiations(...)
        [HOME]/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:47
cmd/compile/internal/noder.(*irgen).generate(0xc000444000, {0xc000056bd0, 0x2, 0x203000?})
        [HOME]/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:320 +0x3db
cmd/compile/internal/noder.check2({0xc000056bd0, 0x2, 0x2})
        [HOME]/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc00001e220, 0x2, 0x0?})
        [HOME]/sdk/gotip/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0x19379e8)
        [HOME]/sdk/gotip/src/cmd/compile/internal/gc/main.go:191 +0xb13
main.main()
        [HOME]/sdk/gotip/src/cmd/compile/main.go:55 +0xdd

In src/cmd/compile/internal/noder/stencil.go:626 looks like nameNode or nameNode.Func is nil.

// checkFetchBody checks if a generic body can be fetched, but hasn't been loaded
// yet. If so, it imports the body.
func checkFetchBody(nameNode *ir.Name) {
        if nameNode.Func.Body == nil && nameNode.Func.Inl != nil {
                // If there is no body yet but Func.Inl exists, then we can can
                // import the whole generic body.
                assert(nameNode.Func.Inl.Cost == 1 && nameNode.Sym().Pkg != types.LocalPkg)
@cloneable cloneable changed the title cmd/compile: SIGSEGV in noder.checkFetchBody. noder.checkFetchBody is nil? cmd/compile: SIGSEGV in noder.checkFetchBody Oct 31, 2021
@cuonglm cuonglm added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 31, 2021
@cuonglm cuonglm added this to the Go1.18 milestone Oct 31, 2021
@gopherbot
Copy link

Change https://golang.org/cl/360056 mentions this issue: cmd/compile: fix panic in checkFetchBody

@golang golang locked and limited conversation to collaborators Nov 2, 2022
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
None yet
Development

No branches or pull requests

3 participants