golang/go

cmd/compile: internal compiler error: panic during prove

Closed this issue · 4 comments

$ gotip version
go version devel go1.24-760b722c Fri Aug 9 14:54:31 2024 +0000 linux/amd64
package p

var v []func()

func f(i int) {
	v = make([]func(), -2|i)
}
$ gotip build crash.go
# command-line-arguments
./crash.go:7:1: internal compiler error: 'f': panic during prove while compiling f:

runtime error: invalid memory address or nil pointer dereference

goroutine 9 [running]:
cmd/compile/internal/ssa.Compile.func1()
	./desktop/gotip/src/cmd/compile/internal/ssa/compile.go:49 +0x6c
panic({0xdacd40?, 0x14e8b40?})
	./desktop/gotip/src/runtime/panic.go:785 +0x132
cmd/compile/internal/ssa.removeBranch(0x0, 0x0)
	./desktop/gotip/src/cmd/compile/internal/ssa/prove.go:2160 +0x22

...

The reason it is panicking is because prove thinks the first block of the function is unreachable. I think there is some confusion lurking here between "unreachable" and "unconditionally panics" (the first block of f is the latter, but it isn't the former).

This is maybe a better example:

package p

var v []func()

func f(i, j int) {
	if j > 0 {
		v = make([]func(), -2|i)
	}
}

This function currently compiles to just RET. It should compile to something that will panic if j>0.

Change https://go.dev/cl/604118 mentions this issue: cmd/compile: in prove pass, check for unsat before adding local facts