golang/go

cmd/compile: internal compiler error: panic: runtime error when clearing empty struct slice

ALTree opened this issue · 3 comments

$ gotip version
go version devel go1.21-18e17e2 Thu Jun 29 23:06:46 2023 +0000 linux/amd64

$ go version
go version go1.21rc2 linux/amd64
package main

var V = []struct{}{}

func main() {
	clear(V)
}
$ gotip build crash.go 
# command-line-arguments
./crash.go:6:7: internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference

goroutine 1 [running]:
runtime/debug.Stack()
	./desktop/gotip/src/runtime/debug/stack.go:24 +0x5e
cmd/compile/internal/base.FatalfAt({0x2?, 0x3050?}, {0xd6cf86, 0x9}, {0xc0000ef428, 0x1, 0x1})
	./desktop/gotip/src/cmd/compile/internal/base/print.go:230 +0x1d7
cmd/compile/internal/base.Fatalf(...)
	./desktop/gotip/src/cmd/compile/internal/base/print.go:199
cmd/compile/internal/gc.handlePanic()
	./desktop/gotip/src/cmd/compile/internal/gc/main.go:52 +0x90
panic({0xcef740?, 0x13a0cb0?})
	./desktop/gotip/src/runtime/panic.go:914 +0x21f
cmd/compile/internal/walk.walkExpr({0xecec78, 0xc00040b1d0}, 0xc0000ef838)
	./desktop/gotip/src/cmd/compile/internal/walk/expr.go:59 +0x2e7
cmd/compile/internal/walk.walkStmt({0xecec78, 0xc00040b1d0?})
	./desktop/gotip/src/cmd/compile/internal/walk/stmt.go:59 +0x87a
cmd/compile/internal/walk.walkStmtList(...)
	./desktop/gotip/src/cmd/compile/internal/walk/stmt.go:175
cmd/compile/internal/walk.Walk(0xc00042b4a0)
	./desktop/gotip/src/cmd/compile/internal/walk/walk.go:43 +0x14d
cmd/compile/internal/gc.prepareFunc(0xc00042b4a0)
	./desktop/gotip/src/cmd/compile/internal/gc/compile.go:105 +0xf9
cmd/compile/internal/gc.enqueueFunc(0xc00042b4a0)
	./desktop/gotip/src/cmd/compile/internal/gc/compile.go:71 +0x307
cmd/compile/internal/gc.Main(0xda4168)
	./desktop/gotip/src/cmd/compile/internal/gc/main.go:338 +0x14dd
main.main()
	./desktop/gotip/src/cmd/compile/main.go:57 +0xf9

Affects both tip and 1.21rc2

cc @griesemer @mdempsky

/cc @golang/compiler

Change https://go.dev/cl/507535 mentions this issue: cmd/compile: fix clear on slice with zero size elem

Change https://go.dev/cl/508335 mentions this issue: test: add test cases for index value with range array clear