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: crash in regalloc #15585

Closed
MichaelTJones opened this issue May 6, 2016 · 4 comments
Closed

cmd/compile: crash in regalloc #15585

MichaelTJones opened this issue May 6, 2016 · 4 comments
Milestone

Comments

@MichaelTJones
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version devel +83676d6 Fri May 6 19:27:45 2016 +0000 darwin/amd64

  2. What operating system and processor architecture are you using (go env)?
    $ go env
    GOARCH="amd64"
    GOBIN=""
    GOEXE=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOOS="darwin"
    GOPATH="/Users/mtj/gocode"
    GORACE=""
    GOROOT="/Users/mtj/go"
    GOTOOLDIR="/Users/mtj/go/pkg/tool/darwin_amd64"
    CC="clang"
    GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6w/y_5pxjsx4h1dhpyrlgq70qt80000gn/T/go-build580720697=/tmp/go-build -gno-record-gcc-switches -fno-common"
    CXX="clang++"
    CGO_ENABLED="1"

  3. What did you do?
    Compiled after a trivial change to a working program.
    https://play.golang.org/p/G4wvi6aza1
    put in a directory, build ==> compiler dies.

  4. What did you expect to see?
    happiness

  5. What did you see instead?

    $ go build bug.go
    # command-line-arguments
    ./bug.go:9: internal compiler error: panic during regalloc while compiling example:

    runtime error: index out of range

    goroutine 1 [running]:
    cmd/compile/internal/ssa.Compile.func1(0xc8204c8e08, 0xc82001a3c0)
    /Users/mtj/go/src/cmd/compile/internal/ssa/compile.go:35 +0xab
    panic(0x47aa20, 0xc820010140)
    /Users/mtj/go/src/runtime/panic.go:458 +0x226
    cmd/compile/internal/ssa.(*regAllocState).regalloc(0xc8200d6780, 0xc82001a3c0)
    /Users/mtj/go/src/cmd/compile/internal/ssa/regalloc.go:1324 +0x4311
    cmd/compile/internal/ssa.regalloc(0xc82001a3c0)
    /Users/mtj/go/src/cmd/compile/internal/ssa/regalloc.go:134 +0x64
    cmd/compile/internal/ssa.Compile(0xc82001a3c0)
    /Users/mtj/go/src/cmd/compile/internal/ssa/compile.go:64 +0x2cb
    cmd/compile/internal/gc.buildssa(0xc820417ef0, 0x0)
    /Users/mtj/go/src/cmd/compile/internal/gc/ssa.go:228 +0x8b8
    cmd/compile/internal/gc.compile(0xc820417ef0)
    /Users/mtj/go/src/cmd/compile/internal/gc/pgen.go:405 +0x12f9
    cmd/compile/internal/gc.funccompile(0xc820417ef0)
    /Users/mtj/go/src/cmd/compile/internal/gc/dcl.go:1278 +0x178
    cmd/compile/internal/gc.Main()
    /Users/mtj/go/src/cmd/compile/internal/gc/main.go:464 +0x1953
    cmd/compile/internal/amd64.Main()
    /Users/mtj/go/src/cmd/compile/internal/amd64/galign.go:96 +0x381
    main.main()
    /Users/mtj/go/src/cmd/compile/main.go:33 +0x286

    goroutine 1 [running]:
    runtime/debug.Stack(0x0, 0x0, 0x0)
    /Users/mtj/go/src/runtime/debug/stack.go:24 +0x6f
    cmd/compile/internal/gc.Fatalf(0x4cad80, 0x2c, 0xc8204f8040, 0x4, 0x4)
    /Users/mtj/go/src/cmd/compile/internal/gc/subr.go:158 +0x236
    cmd/compile/internal/gc.(_ssaExport).Fatalf(0x710ae8, 0xc800000009, 0x4cad80, 0x2c, 0xc8204f8040, 0x4, 0x4)
    /Users/mtj/go/src/cmd/compile/internal/gc/ssa.go:4398 +0x65
    cmd/compile/internal/ssa.(_Config).Fatalf(0xc82044c000, 0x9, 0x4cad80, 0x2c, 0xc8204f8040, 0x4, 0x4)
    /Users/mtj/go/src/cmd/compile/internal/ssa/config.go:181 +0x64
    cmd/compile/internal/ssa.(_Func).Fatalf(0xc82001a3c0, 0x4cad80, 0x2c, 0xc8204f8040, 0x4, 0x4)
    /Users/mtj/go/src/cmd/compile/internal/ssa/func.go:393 +0x61
    cmd/compile/internal/ssa.Compile.func1(0xc8204c8e08, 0xc82001a3c0)
    /Users/mtj/go/src/cmd/compile/internal/ssa/compile.go:37 +0x23e
    panic(0x47aa20, 0xc820010140)
    /Users/mtj/go/src/runtime/panic.go:458 +0x226
    cmd/compile/internal/ssa.(_regAllocState).regalloc(0xc8200d6780, 0xc82001a3c0)
    /Users/mtj/go/src/cmd/compile/internal/ssa/regalloc.go:1324 +0x4311
    cmd/compile/internal/ssa.regalloc(0xc82001a3c0)
    /Users/mtj/go/src/cmd/compile/internal/ssa/regalloc.go:134 +0x64
    cmd/compile/internal/ssa.Compile(0xc82001a3c0)
    /Users/mtj/go/src/cmd/compile/internal/ssa/compile.go:64 +0x2cb
    cmd/compile/internal/gc.buildssa(0xc820417ef0, 0x0)
    /Users/mtj/go/src/cmd/compile/internal/gc/ssa.go:228 +0x8b8
    cmd/compile/internal/gc.compile(0xc820417ef0)
    /Users/mtj/go/src/cmd/compile/internal/gc/pgen.go:405 +0x12f9
    cmd/compile/internal/gc.funccompile(0xc820417ef0)
    /Users/mtj/go/src/cmd/compile/internal/gc/dcl.go:1278 +0x178
    cmd/compile/internal/gc.Main()
    /Users/mtj/go/src/cmd/compile/internal/gc/main.go:464 +0x1953
    cmd/compile/internal/amd64.Main()
    /Users/mtj/go/src/cmd/compile/internal/amd64/galign.go:96 +0x381
    main.main()
    /Users/mtj/go/src/cmd/compile/main.go:33 +0x286

@bradfitz bradfitz changed the title Crash in go compiler at tip cmd/compile: crash in regalloc May 6, 2016
@bradfitz bradfitz added this to the Go1.7 milestone May 6, 2016
@dr2chase
Copy link
Contributor

dr2chase commented May 6, 2016

@randall77 - have you started on this?
Seems to be failure to guard some sparse set ops, though there may be a root cause we need to look at:

diff --git a/src/cmd/compile/internal/ssa/sparsemap.go b/src/cmd/compile/internal/ssa/sparsemap.go
index 0211a70..e22ed1e 100644
--- a/src/cmd/compile/internal/ssa/sparsemap.go
+++ b/src/cmd/compile/internal/ssa/sparsemap.go
@@ -67,6 +67,9 @@ func (s *sparseMap) setBit(k ID, v uint) {
 }

 func (s *sparseMap) remove(k ID) {
+       if k >= ID(len(s.sparse)) {
+               return
+       }
        i := s.sparse[k]
        if i < len(s.dense) && s.dense[i].key == k {
                y := s.dense[len(s.dense)-1]
diff --git a/src/cmd/compile/internal/ssa/sparseset.go b/src/cmd/compile/internal/ssa/sparseset.go
index 66bebf1..f018563 100644
--- a/src/cmd/compile/internal/ssa/sparseset.go
+++ b/src/cmd/compile/internal/ssa/sparseset.go
@@ -53,6 +53,9 @@ func (s *sparseSet) addAllValues(a []*Value) {
 }

 func (s *sparseSet) remove(x ID) {
+       if x >= ID(len(s.sparse)) {
+               return
+       }
        i := s.sparse[x]
        if i < len(s.dense) && s.dense[i] == x {
                y := s.dense[len(s.dense)-1]

@dr2chase
Copy link
Contributor

dr2chase commented May 6, 2016

uh, yeah. We preallocate a sparseset for as many values as we've got, then we create more values.

@dr2chase dr2chase assigned dr2chase and unassigned randall77 May 7, 2016
@MichaelTJones
Copy link
Contributor Author

Cool! Fixed already!

https://go-review.googlesource.com/22911
Gerrit-Reviewer: Cherry Zhang cherryyz@google.com
Gerrit-Reviewer: David Chase drchase@google.com
Gerrit-Reviewer: Keith Randall khr@golang.org
Gerrit-Reviewer: Russ Cox rsc@golang.org

@gopherbot
Copy link

CL https://golang.org/cl/22911 mentions this issue.

@golang golang locked and limited conversation to collaborators May 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants