cmd/compile: internal compiler error: panic during layout
ALTree opened this issue · 7 comments
$ gotip version
go version devel +6104939432 Sun Jan 21 04:56:36 2018 +0000 linux/amd64
The following program:
package p
func f() {
var B bool
B2 := (B || B && !B) && !B
B3 := B2 || B
for (B3 || B2) && !B2 && B {
}
}
crashes the go1.6, go1.7, go1.8, go1.9, and tip compilers with the following error:
# command-line-arguments
./prog.go:7:2: internal compiler error: panic during layout while compiling f:
runtime error: index out of range
goroutine 18 [running]:
cmd/compile/internal/ssa.Compile.func1(0xc420359288, 0xc42035c140)
/home/adonizetti/go/src/cmd/compile/internal/ssa/compile.go:38 +0xc8
panic(0xbbb7e0, 0xf9c810)
/home/adonizetti/go/src/runtime/panic.go:502 +0x229
cmd/compile/internal/ssa.layout(0xc42035c140)
/home/adonizetti/go/src/cmd/compile/internal/ssa/layout.go:68 +0xdca
cmd/compile/internal/ssa.Compile(0xc42035c140)
/home/adonizetti/go/src/cmd/compile/internal/ssa/compile.go:70 +0x2bb
cmd/compile/internal/gc.buildssa(0xc420001200, 0x0, 0x0)
/home/adonizetti/go/src/cmd/compile/internal/gc/ssa.go:223 +0xb32
cmd/compile/internal/gc.compileSSA(0xc420001200, 0x0)
/home/adonizetti/go/src/cmd/compile/internal/gc/pgen.go:239 +0x39
cmd/compile/internal/gc.compileFunctions.func2(0xc4204a83c0, 0xc420492090, 0x0)
/home/adonizetti/go/src/cmd/compile/internal/gc/pgen.go:289 +0x49
created by cmd/compile/internal/gc.compileFunctions
/home/adonizetti/go/src/cmd/compile/internal/gc/pgen.go:287 +0x11c
cc @randall77
Has this input program already been minified somehow? I can't seem to minify it in any way.
Has this input program already been minified somehow?
Yes. When posting these I usually try to minimize the reproducer before opening an issue.
Thanks for the report.
Looks like a simple invariant mistake.
The layout code assumes that if a branch prediction is marked for a block, that it must have 2 successors. However, the fuse optimization pass deletes successors and doesn't clear the branch prediction bit when it does that.
Should be simple to fix.
(Doesn't crash 1.6. Starts failing for 1.7.)
Change https://golang.org/cl/88955 mentions this issue: cmd/compile: reset branch prediction when deleting a branch
Change https://golang.org/cl/88956 mentions this issue: cmd/compile: constant fold !true and !false
Change https://golang.org/cl/128855 mentions this issue: [release-branch.go1.10] cmd/compile: reset branch prediction when deleting a branch