Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: internal compiler error: panic during layout #23504

Closed
ALTree opened this issue Jan 22, 2018 · 7 comments

Comments

Projects
None yet
4 participants
@ALTree
Copy link
Member

commented Jan 22, 2018

$ 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

@ALTree ALTree added this to the Go1.11 milestone Jan 22, 2018

@ALTree

This comment has been minimized.

Copy link
Member Author

commented Jan 22, 2018

@mvdan

This comment has been minimized.

Copy link
Member

commented Jan 22, 2018

Has this input program already been minified somehow? I can't seem to minify it in any way.

@ALTree

This comment has been minimized.

Copy link
Member Author

commented Jan 22, 2018

Has this input program already been minified somehow?

Yes. When posting these I usually try to minimize the reproducer before opening an issue.

@randall77

This comment has been minimized.

Copy link
Contributor

commented Jan 22, 2018

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.)

@randall77 randall77 self-assigned this Jan 22, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Jan 22, 2018

Change https://golang.org/cl/88955 mentions this issue: cmd/compile: reset branch prediction when deleting a branch

@gopherbot

This comment has been minimized.

Copy link

commented Jan 22, 2018

Change https://golang.org/cl/88956 mentions this issue: cmd/compile: constant fold !true and !false

gopherbot pushed a commit that referenced this issue Feb 14, 2018

cmd/compile: constant fold !true and !false
Constant fold Not of boolean constants.

Noticed while working on #23504.

Change-Id: I965705154ee7348a1a159fad4e029b922d3171b3
Reviewed-on: https://go-review.googlesource.com/88956
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>

@gopherbot gopherbot closed this in 4313d77 Feb 20, 2018

cwedgwood added a commit to cwedgwood/go that referenced this issue Apr 18, 2018

cmd/compile: reset branch prediction when deleting a branch
When we go from a branch block to a plain block, reset the
branch prediction bit. Downstream passes asssume that if the
branch prediction is set, then the block has 2 successors.

Fixes golang#23504

Change-Id: I2898ec002228b2e34fe80ce420c6939201c0a5aa
Reviewed-on: https://go-review.googlesource.com/88955
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
@gopherbot

This comment has been minimized.

Copy link

commented Aug 9, 2018

Change https://golang.org/cl/128855 mentions this issue: [release-branch.go1.10] cmd/compile: reset branch prediction when deleting a branch

gopherbot pushed a commit that referenced this issue Aug 9, 2018

[release-branch.go1.10] cmd/compile: reset branch prediction when del…
…eting a branch

When we go from a branch block to a plain block, reset the
branch prediction bit. Downstream passes asssume that if the
branch prediction is set, then the block has 2 successors.

Fixes #23504
Fixes #26851

Change-Id: I2898ec002228b2e34fe80ce420c6939201c0a5aa
Reviewed-on: https://go-review.googlesource.com/88955
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
(cherry picked from commit 4313d77)
Reviewed-on: https://go-review.googlesource.com/128855
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.