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: panic: runtime error: invalid memory address or nil pointer dereference #51335

Closed
dominikh opened this issue Feb 23, 2022 · 6 comments
Labels
NeedsFix release-blocker
Milestone

Comments

@dominikh
Copy link
Member

@dominikh dominikh commented Feb 23, 2022

Input:

package pkg

type S1 struct{ X int }

func foo[T *S1|S1]() {
	_= []T{{1}}
}

Output:

$ go build bar.go
# command-line-arguments
<unknown line number>: internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference

goroutine 1 [running]:
runtime/debug.Stack()
	/home/dominikh/prj/go/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x211d3fff?, 0x7fd0?}, {0xd22189, 0x9}, {0xc0000efec8, 0x1, 0x1})
	/home/dominikh/prj/go/src/cmd/compile/internal/base/print.go:227 +0x1d7
cmd/compile/internal/base.Fatalf(...)
	/home/dominikh/prj/go/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/gc.handlePanic()
	/home/dominikh/prj/go/src/cmd/compile/internal/gc/main.go:49 +0x85
panic({0xcaba20, 0x1311df0})
	/home/dominikh/prj/go/src/runtime/panic.go:838 +0x207
cmd/compile/internal/types2.(*Checker).handleBailout(0xc00045e000, 0xc0000f1648)
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/check.go:283 +0x8b
panic({0xcaba20, 0x1311df0})
	/home/dominikh/prj/go/src/runtime/panic.go:838 +0x207
cmd/compile/internal/types2.under({0x0?, 0x0?})
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/type.go:27 +0x4f
cmd/compile/internal/types2.coreType({0x0?, 0x0?})
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/type.go:39 +0x9a
cmd/compile/internal/types2.(*Checker).exprInternal(0xc00045e000, 0xc0000e5b40, {0xe95be8?, 0xc000451c70}, {0xe94d80?, 0xc000427380?})
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/expr.go:1370 +0x293
cmd/compile/internal/types2.(*Checker).rawExpr(0xc00045e000, 0xc0000e5b40, {0xe95be8?, 0xc000451c70?}, {0xe94d80?, 0xc000427380?}, 0x0)
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/expr.go:1225 +0x1a5
cmd/compile/internal/types2.(*Checker).exprWithHint(0xca8d40?, 0xc0000f07e8?, {0xe95be8?, 0xc000451c70?}, {0xe94d80?, 0xc000427380?})
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/expr.go:1774 +0x46
cmd/compile/internal/types2.(*Checker).indexedElts(0xe94d08?, {0xc0000bac00, 0x1, 0xc00002d07c?}, {0xe94d80, 0xc000427380}, 0xffffffffffffffff)
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/index.go:462 +0x4cc
cmd/compile/internal/types2.(*Checker).exprInternal(0xc00045e000, 0xc0000e5ac0, {0xe95be8?, 0xc000451c20}, {0x0?, 0x0?})
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/expr.go:1481 +0x645
cmd/compile/internal/types2.(*Checker).rawExpr(0xc00045e000, 0xc0000e5ac0, {0xe95be8?, 0xc000451c20?}, {0x0?, 0x0?}, 0x0)
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/expr.go:1225 +0x1a5
cmd/compile/internal/types2.(*Checker).multiExpr(0x1?, 0xc0000f0e60?, {0xe95be8?, 0xc000451c20?})
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/expr.go:1764 +0x35
cmd/compile/internal/types2.(*Checker).exprList(0x0?, {0xc0000f1198?, 0xc000000718?, 0xc0000005a0?}, 0x0)
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/call.go:250 +0x97
cmd/compile/internal/types2.(*Checker).assignVars(0xc00045e000, {0xc0000f11a8?, 0x1, 0x1}, {0xc0000f1198?, 0x1, 0x1})
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/assignments.go:392 +0x85
cmd/compile/internal/types2.(*Checker).stmt(0xc00045e000, 0x0, {0xe95a68?, 0xc0000e5880?})
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/stmt.go:452 +0x405
cmd/compile/internal/types2.(*Checker).stmtList(0xe94510?, 0x0, {0xc0000bac10?, 0x203000?, 0x203000?})
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/stmt.go:124 +0xc9
cmd/compile/internal/types2.(*Checker).funcBody(0xc00045e000, 0xc0000c7c20, {0xc00002d083?, 0xc00042fd80?}, 0xc0000e5900, 0xc0000e5840, {0x0, 0x0})
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/stmt.go:45 +0x3fb
cmd/compile/internal/types2.(*Checker).funcDecl.func1()
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/decl.go:718 +0x45
cmd/compile/internal/types2.(*Checker).processDelayed(0xc00045e000, 0x0)
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/check.go:369 +0x44
cmd/compile/internal/types2.(*Checker).checkFiles(0xc00045e000, {0xc00000e480, 0x1, 0x1})
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/check.go:316 +0x172
cmd/compile/internal/types2.(*Checker).Files(...)
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/check.go:288
cmd/compile/internal/types2.(*Config).Check(0xca95e0?, {0x7fff95b94f0f?, 0xd1db3e?}, {0xc00000e480, 0x1, 0x1}, 0x600c0003fe690?)
	/home/dominikh/prj/go/src/cmd/compile/internal/types2/api.go:420 +0x70
cmd/compile/internal/noder.checkFiles({0xc00000e450, 0x1, 0x203000?})
	/home/dominikh/prj/go/src/cmd/compile/internal/noder/irgen.go:65 +0x49c
cmd/compile/internal/noder.check2({0xc00000e450, 0x1, 0x1})
	/home/dominikh/prj/go/src/cmd/compile/internal/noder/irgen.go:78 +0x46
cmd/compile/internal/noder.LoadPackage({0xc00001e2f0, 0x1, 0x0?})
	/home/dominikh/prj/go/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0xd52330)
	/home/dominikh/prj/go/src/cmd/compile/internal/gc/main.go:191 +0xb13
main.main()
	/home/dominikh/prj/go/src/cmd/compile/main.go:55 +0xdd
@dominikh dominikh added the NeedsInvestigation label Feb 23, 2022
@dominikh dominikh added this to the Go1.18 milestone Feb 23, 2022
@dominikh
Copy link
Member Author

@dominikh dominikh commented Feb 23, 2022

Same crash, slightly less weird code:

package pkg

type S1 struct{ X int }
type S2 struct{ X int }

func foo[T *S1|*S2]() {
	_= []T{{1}}
}

@findleyr
Copy link
Contributor

@findleyr findleyr commented Feb 23, 2022

CC @griesemer

@findleyr
Copy link
Contributor

@findleyr findleyr commented Feb 23, 2022

Conservatively marking as a release blocker until we understand this.

@findleyr
Copy link
Contributor

@findleyr findleyr commented Feb 23, 2022

I looked into this superficially. This code assumes that the type hint has a core type:
https://cs.opensource.google/go/go/+/master:src/cmd/compile/internal/types2/expr.go;l=1362;drc=master

This appears straightforward to fix, and is a crasher. We should fix for 1.18.

EDIT: and thank you @dominikh for the report!

@griesemer griesemer self-assigned this Feb 23, 2022
@griesemer
Copy link
Contributor

@griesemer griesemer commented Feb 23, 2022

Agreed. Coming to the same conclusion @findleyr . Seems easy to fix.

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 23, 2022

Change https://go.dev/cl/387676 mentions this issue: go/types, types2: don't crash if comp. literal element type has no core type

@griesemer griesemer added NeedsFix and removed NeedsInvestigation labels Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants