golang/go

cmd/compile: internal compiler error: panic during short circuit

ALTree opened this issue · 4 comments

$ gotip version
go version devel +7be97af2ff Wed Aug 28 05:55:52 2019 +0000 windows/amd64

The following program:

package p

func f() {
        var p, q bool
        for {
                p = p && q
        }
}

Crashes the tip compiler with the following error:

$ gotip tool compile crash.go
crash.go:5:2: internal compiler error: 'f': panic during short circuit while compiling f:

runtime error: index out of range [2] with length 2

goroutine 1 [running]:
cmd/compile/internal/ssa.Compile.func1(0xc00008c728, 0xc0002bc580)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/ssa/compile.go:47 +0xac
panic(0xe1a8a0, 0xc000064b60)
        D:/users/ZZZZZ/alberto/other/temp/go/src/runtime/panic.go:679 +0x1c0
cmd/compile/internal/ssa.shortcircuitBlock(0xc000378e60, 0xc000000800)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/ssa/shortcircuit.go:160 +0x5f7
cmd/compile/internal/ssa.shortcircuit(0xc0002bc580)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/ssa/shortcircuit.go:69 +0x364
cmd/compile/internal/ssa.Compile(0xc0002bc580)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/ssa/compile.go:92 +0x99b
cmd/compile/internal/gc.buildssa(0xc0002bc160, 0x0, 0x0)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/gc/ssa.go:289 +0xc15
cmd/compile/internal/gc.compileSSA(0xc0002bc160, 0x0)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/gc/pgen.go:298 +0x54
cmd/compile/internal/gc.compile(0xc0002bc160)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/gc/pgen.go:277 +0x33b
cmd/compile/internal/gc.funccompile(0xc0002bc160)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/gc/pgen.go:222 +0xc8
cmd/compile/internal/gc.Main(0xe74da8)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/gc/main.go:685 +0x31de
main.main()
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/main.go:51 +0xb3

goroutine 1 [running]:
runtime/debug.Stack(0xff6be0, 0xc000090008, 0x0)
        D:/users/ZZZZZ/alberto/other/temp/go/src/runtime/debug/stack.go:24 +0xa4
cmd/compile/internal/gc.Fatalf(0xc00007c140, 0x32, 0xc00009c4b0, 0x5, 0x5)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/gc/subr.go:188 +0x298
cmd/compile/internal/gc.(*ssafn).Fatalf(0xc00006d8f0, 0x502100000002, 0xe6a2b2, 0x2c, 0xc000314c00, 0x4, 0x4)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/gc/ssa.go:6159 +0x1b7
cmd/compile/internal/ssa.(*Func).Fatalf(...)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/ssa/func.go:617
cmd/compile/internal/ssa.Compile.func1(0xc00008c728, 0xc0002bc580)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/ssa/compile.go:49 +0x21d
panic(0xe1a8a0, 0xc000064b60)
        D:/users/ZZZZZ/alberto/other/temp/go/src/runtime/panic.go:679 +0x1c0
cmd/compile/internal/ssa.shortcircuitBlock(0xc000378e60, 0xc000000800)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/ssa/shortcircuit.go:160 +0x5f7
cmd/compile/internal/ssa.shortcircuit(0xc0002bc580)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/ssa/shortcircuit.go:69 +0x364
cmd/compile/internal/ssa.Compile(0xc0002bc580)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/ssa/compile.go:92 +0x99b
cmd/compile/internal/gc.buildssa(0xc0002bc160, 0x0, 0x0)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/gc/ssa.go:289 +0xc15
cmd/compile/internal/gc.compileSSA(0xc0002bc160, 0x0)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/gc/pgen.go:298 +0x54
cmd/compile/internal/gc.compile(0xc0002bc160)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/gc/pgen.go:277 +0x33b
cmd/compile/internal/gc.funccompile(0xc0002bc160)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/gc/pgen.go:222 +0xc8
cmd/compile/internal/gc.Main(0xe74da8)
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/internal/gc/main.go:685 +0x31de
main.main()
        D:/users/ZZZZZ/alberto/other/temp/go/src/cmd/compile/main.go:51 +0xb3

It compiles fine on go1.12.5.

It appears that the issue was introduced in the recently committed 52ae04f (cmd/compile: improve shortcircuit pass).

cc @josharian

Thanks! I’ll look soon.

Change https://golang.org/cl/192144 mentions this issue: cmd/compile: handle infinite loops in shortcircuit pass