$ 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

...

Comment From: ALTree

cc @randall77

Comment From: gabyhelp

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: randall77

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.

Comment From: gopherbot

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