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: nil pointer dereference #47892

Closed
scott-cotton opened this issue Aug 22, 2021 · 10 comments
Closed

cmd/compile: nil pointer dereference #47892

scott-cotton opened this issue Aug 22, 2021 · 10 comments

Comments

@scott-cotton
Copy link

@scott-cotton scott-cotton commented Aug 22, 2021

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

$ go version
go version devel go1.18-6e50991d2a Sat Aug 21 18:23:58 2021 +0000 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/scott/Library/Caches/go-build"
GOENV="/Users/scott/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/scott/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/scott/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/scott/Dev/goroot"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/scott/Dev/goroot/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="devel go1.18-6e50991d2a Sat Aug 21 18:23:58 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/scott/Dev/github.com/go-air/pal/go.mod"
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/8l/sr00g88x14j75srnmv8t416m0000gn/T/go-build303100628=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

tried to build the package "memory" in the dev.typeparams branch of GitHub.com/go-air/pal

git clone https://github.com/go-air/pal.git
cd pal
git checkout dev.typeparams
go build ./memory

What did you expect to see?

not sure, either a compile error or success.

What did you see instead?

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

goroutine 1 [running]:
cmd/compile/internal/typecheck.(*crawler).checkGenericType(0xc000bb5c70, 0x11b0b47)
/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/crawler.go:227 +0x3b
cmd/compile/internal/typecheck.(*crawler).markInlBody.func1({0x1a5f758, 0xc000bb5c70})
/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/crawler.go:201 +0xb2
cmd/compile/internal/ir.Visit.func1({0x1a5f758, 0xc000bb5c70})
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/visit.go:105 +0x30
cmd/compile/internal/ir.(*StructKeyExpr).doChildren(0xc000bbf270, 0xc000717f38)
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/node_gen.go:1264 +0x62
cmd/compile/internal/ir.DoChildren(...)
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a60310, 0xc000bbf270})
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.doNodes({0xc00092ae10, 0x3, 0x11be217}, 0xc000717f38)
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/node_gen.go:1512 +0x67
cmd/compile/internal/ir.(*CompLitExpr).doChildren(0xc0001c7880, 0xc000717f38)
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/node_gen.go:392 +0x99
cmd/compile/internal/ir.DoChildren(...)
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a5e560, 0xc0001c7880})
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.(*AddrExpr).doChildren(0xc000bbf2c0, 0xc000717f38)
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/node_gen.go:44 +0x62
cmd/compile/internal/ir.DoChildren(...)
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a5da70, 0xc000bbf2c0})
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.(*AssignStmt).doChildren(0xc000bbf360, 0xc000717f38)
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/node_gen.go:152 +0x82
cmd/compile/internal/ir.DoChildren(...)
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a5dd90, 0xc000bbf360})
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.Visit({0x1a5dd90, 0xc000bbf360}, 0xc000717f20)
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/visit.go:108 +0xb8
cmd/compile/internal/ir.VisitList({0xc0001c7980, 0x7, 0xc000722b10}, 0xc00012ecb0)
/Users/scott/Dev/goroot/src/cmd/compile/internal/ir/visit.go:114 +0x65
cmd/compile/internal/typecheck.(*crawler).markInlBody(0xc000e45530, 0xc00012ecb0)
/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/crawler.go:217 +0x22d
cmd/compile/internal/typecheck.(*crawler).markObject(0xc0000a2ed0, 0xc000bb5ad0)
/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/crawler.go:35 +0x2f
cmd/compile/internal/typecheck.crawlExports({0xc000626e00, 0x1c, 0x10de473})
/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/crawler.go:23 +0x9f
cmd/compile/internal/typecheck.WriteExports({0x1a456e0, 0xc000722ab0}, 0x1)
/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/iexport.go:273 +0x65
cmd/compile/internal/noder.WriteExports(0xc000e454c0)
/Users/scott/Dev/goroot/src/cmd/compile/internal/noder/export.go:40 +0x7a
cmd/compile/internal/gc.dumpCompilerObj(0xc000e454c0)
/Users/scott/Dev/goroot/src/cmd/compile/internal/gc/obj.go:107 +0x28
cmd/compile/internal/gc.dumpobj1({0x206371401, 0x50}, 0x3)
/Users/scott/Dev/goroot/src/cmd/compile/internal/gc/obj.go:63 +0x185
cmd/compile/internal/gc.dumpobj()
/Users/scott/Dev/goroot/src/cmd/compile/internal/gc/obj.go:44 +0x36
cmd/compile/internal/gc.Main(0x1918b50)
/Users/scott/Dev/goroot/src/cmd/compile/internal/gc/main.go:322 +0x10d6
main.main()
/Users/scott/Dev/goroot/src/cmd/compile/main.go:55 +0xdd

@scott-cotton scott-cotton mentioned this issue Aug 22, 2021
4 tasks
@seankhliao seankhliao changed the title typeparams compile bug cmd/compile: nil pointer dereference Aug 22, 2021
@randall77
Copy link
Contributor

@randall77 randall77 commented Aug 24, 2021

I'm not able to reproduce at tip (I get a compile error, not an ICE, which is expected).
Are you still seeing this?

Loading

@scott-cotton
Copy link
Author

@scott-cotton scott-cotton commented Aug 24, 2021

I am still getting the error, at
go version devel go1.18-4a9f0cec29 Tue Aug 24 18:02:21 2021 +0000 darwin/amd64

I will see if I can narrow it down to a smaller case.

Loading

@scott-cotton
Copy link
Author

@scott-cotton scott-cotton commented Aug 24, 2021

Not sure if it is related (but looks likely). The attached smaller self contained example gives this

scott@pavillion 47892 % go version
go version devel go1.18-4a9f0cec29 Tue Aug 24 18:02:21 2021 +0000 darwin/amd64
scott@pavillion 47892 % go build ./b
# tpcrash/b
panic: interface conversion: types.Object is nil, not *ir.Name

goroutine 1 [running]:
cmd/compile/internal/typecheck.(*exportWriter).doTyp(0xc0004195e0, 0xc000418770)
	/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/iexport.go:898 +0xc7b
cmd/compile/internal/typecheck.(*iexporter).typOff(0xc0003a2210, 0xc000418770)
	/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/iexport.go:864 +0x88
cmd/compile/internal/typecheck.(*exportWriter).typ(0xc0004184d0, 0xc0004405f0)
	/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/iexport.go:711 +0x25
cmd/compile/internal/typecheck.(*exportWriter).doTyp(0xc0004184d0, 0xc000418d20)
	/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/iexport.go:965 +0x83e
cmd/compile/internal/typecheck.(*iexporter).typOff(0xc0003a2210, 0xc000418d20)
	/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/iexport.go:864 +0x88
cmd/compile/internal/typecheck.(*exportWriter).typ(0xc0004183f0, 0xc00012a5e0)
	/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/iexport.go:711 +0x25
cmd/compile/internal/typecheck.(*iexporter).doDecl(0xc0003a2210, 0xc000446000)
	/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/iexport.go:569 +0x485
cmd/compile/internal/typecheck.WriteExports({0x1a470c0, 0xc000406f90}, 0x1)
	/Users/scott/Dev/goroot/src/cmd/compile/internal/typecheck/iexport.go:301 +0x2eb
cmd/compile/internal/noder.WriteExports(0xc00010a290)
	/Users/scott/Dev/goroot/src/cmd/compile/internal/noder/export.go:40 +0x7a
cmd/compile/internal/gc.dumpCompilerObj(0xc00010a290)
	/Users/scott/Dev/goroot/src/cmd/compile/internal/gc/obj.go:107 +0x28
cmd/compile/internal/gc.dumpobj1({0x2063a15a1, 0x4f}, 0x3)
	/Users/scott/Dev/goroot/src/cmd/compile/internal/gc/obj.go:63 +0x185
cmd/compile/internal/gc.dumpobj()
	/Users/scott/Dev/goroot/src/cmd/compile/internal/gc/obj.go:44 +0x36
cmd/compile/internal/gc.Main(0x1919e10)
	/Users/scott/Dev/goroot/src/cmd/compile/internal/gc/main.go:322 +0x10d6
main.main()
	/Users/scott/Dev/goroot/src/cmd/compile/main.go:55 +0xdd

47892.zip

Loading

@scott-cotton
Copy link
Author

@scott-cotton scott-cotton commented Aug 26, 2021

I can confirm that the attached example above still crashes after the last round of typeparams fixes, with the same traceback.

scott@pavillion 47892 % go version
go version devel go1.18-4f2620285d Wed Aug 25 23:44:02 2021 +0000 darwin/amd64

@randall77 are you still waiting for info?

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 26, 2021

Change https://golang.org/cl/345229 mentions this issue: cmd/compile: set OrigSym.Def after create a generic named type.

Loading

@wdvxdr1123
Copy link
Contributor

@wdvxdr1123 wdvxdr1123 commented Aug 26, 2021

smaller:

package a

type Index[T any] interface {
	G() T
}

type I1[T any] struct {
	a T
}

func (i *I1[T]) G() T {
	return i.a
}
package main

import "a"

type Model[T any] struct {
	index       a.Index[T]
}

func NewModel[T any](index a.Index[T]) Model[T] {
	return Model[T]{
		index:       index,
	}
}

func main() {
	_ = NewModel[int]((*a.I1[int])(nil))
}

Loading

@scott-cotton
Copy link
Author

@scott-cotton scott-cotton commented Aug 26, 2021

Thanks! the CL above crashes for me on test/typeparams/mdemsky/{7,12}.go

Loading

@wdvxdr1123
Copy link
Contributor

@wdvxdr1123 wdvxdr1123 commented Aug 26, 2021

I upload a new patch which should fix that.

Loading

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Aug 27, 2021

@scott-cotton Sorry, I've tried all of your test cases, and I'm not able to reproduce it locally either.

Loading

@mdempsky mdempsky added this to the Go1.18 milestone Aug 27, 2021
@scott-cotton
Copy link
Author

@scott-cotton scott-cotton commented Aug 28, 2021

@mdempsky thanks much for trying. I just used gotip instead of git pull; ./all.bash and the compile seems to work ok. Not sure if it was my repo or not, but no further need to investigate IMO.

Thanks all

Loading

gopherbot pushed a commit that referenced this issue Aug 29, 2021
This issue has been fixed in https://golang.org/cl/345411

Fixes: #47892

Change-Id: I13dd3814650913da065e5f24a0c61d30adb0633a
Reviewed-on: https://go-review.googlesource.com/c/go/+/345229
Reviewed-by: Dan Scales <danscales@google.com>
Trust: Dan Scales <danscales@google.com>
Trust: Keith Randall <khr@golang.org>
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants