Skip to content

cmd/compile: regression in writebarrier pass #19179

Closed

Description

@dsnet

c4ef597 caused a regression where the following coder no longer compiles:

type Foo struct{ A, B time.Duration }

func Bar(fs []Foo) string {
	ss := make([]string, 2*len(fs))
	for i, h := range fs {
		ss[2*i] = fmt.Sprintf("%v %v", h.A, h.B.Seconds())
		ss[2*i+1] = fmt.Sprintf("%v %v", h.A, h.B.Seconds())
	}
	return strings.Join(ss, ",")
}

It now panics with:

./main.go:16: internal compiler error: attempt to load unspilled value v53 = MOVQload <time.Duration> {h} [8] v2 v117

goroutine 1 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
	/home/rawr/Projects/go/src/runtime/debug/stack.go:24 +0x79
cmd/compile/internal/gc.Fatalf(0xaccaeb, 0x22, 0xc4204a4600, 0x1, 0x1)
	/home/rawr/Projects/go/src/cmd/compile/internal/gc/subr.go:175 +0x230
cmd/compile/internal/gc.(*ssaExport).Fatalf(0xdd0af5, 0x100d00000001, 0xaccaeb, 0x22, 0xc4204a4600, 0x1, 0x1)
	/home/rawr/Projects/go/src/cmd/compile/internal/gc/ssa.go:4929 +0x67
cmd/compile/internal/ssa.(*Config).Fatalf(0xc420452000, 0x100d00000001, 0xaccaeb, 0x22, 0xc4204a4600, 0x1, 0x1)
	/home/rawr/Projects/go/src/cmd/compile/internal/ssa/config.go:345 +0x76
cmd/compile/internal/ssa.(*Func).Fatalf(0xc4204b4000, 0xaccaeb, 0x22, 0xc4204a4600, 0x1, 0x1)
	/home/rawr/Projects/go/src/cmd/compile/internal/ssa/func.go:416 +0x72
cmd/compile/internal/ssa.(*regAllocState).allocValToReg(0xc4204d83c0, 0xc420453988, 0xffce, 0x100000001, 0xc400001233, 0xc4204551e8)
	/home/rawr/Projects/go/src/cmd/compile/internal/ssa/regalloc.go:454 +0x58e
cmd/compile/internal/ssa.(*regAllocState).regalloc(0xc4204d83c0, 0xc4204b4000)
	/home/rawr/Projects/go/src/cmd/compile/internal/ssa/regalloc.go:1188 +0x1731
cmd/compile/internal/ssa.regalloc(0xc4204b4000)
	/home/rawr/Projects/go/src/cmd/compile/internal/ssa/regalloc.go:135 +0x62
cmd/compile/internal/ssa.Compile(0xc4204b4000)
	/home/rawr/Projects/go/src/cmd/compile/internal/ssa/compile.go:70 +0x2c4
cmd/compile/internal/gc.buildssa(0xc4200b9180, 0x0)
	/home/rawr/Projects/go/src/cmd/compile/internal/gc/ssa.go:173 +0x1060
cmd/compile/internal/gc.compile(0xc4200b9180)
	/home/rawr/Projects/go/src/cmd/compile/internal/gc/pgen.go:366 +0x2d0
cmd/compile/internal/gc.funccompile(0xc4200b9180)
	/home/rawr/Projects/go/src/cmd/compile/internal/gc/dcl.go:1226 +0xdc
cmd/compile/internal/gc.Main()
	/home/rawr/Projects/go/src/cmd/compile/internal/gc/main.go:473 +0x202d
main.main()
	/home/rawr/Projects/go/src/cmd/compile/main.go:50 +0x101

\cc @cherrymui @dr2chase @josharian

Activity

  1. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Feb 18, 2017
  2. added this to the Go1.9 milestone on Feb 18, 2017
  3. self-assigned this
    on Feb 19, 2017
  4. gopherbot commented on Feb 19, 2017

    @gopherbot
    Contributor

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

  5. funny-falcon commented on Feb 21, 2017

    @funny-falcon
    Contributor

    Catched with same bit in code with defer.
    Code looks like:

        func (bld *DbBuilder) Finish() error {
            defer bld.Unlink() // <- here is an error
            // ... other code
        }

    Unfortunately, can't build small reproduce case.

  6. funny-falcon commented on Feb 21, 2017

    @funny-falcon
    Contributor

    Changeset 37250 doesn't fix for me at the moment.

    go version devel +5bbe1ce Sat Feb 18 19:44:10 2017 -0500 linux/amd64
    $ go build
    ./builder.go:239: internal compiler error: attempt to load unspilled value v1780 = Phi <int> v282 v449
    ....
    
  7. funny-falcon commented on Feb 21, 2017

    @funny-falcon
    Contributor

    I reduced case to minimal. Looks like removing any line makes it compile

    package dbfile
    
    import (
    	"encoding/binary"
    )
    
    type DbBuilder struct {
    	arr        []int
    }
    
    func (bld *DbBuilder) Finish() error {
    	defer bld.Finish()
    
    	var hash []byte
    	for _, ixw := range bld.arr {
    		for {
    			if ixw != 0 {
    				return nil
    			}
    			ixw--
    		insertOne:
    			for {
    				for i := 0; i < 1; i++ {
    					if binary.LittleEndian.Uint16(hash[i:]) == 0 {
    						break insertOne
    					}
    				}
    			}
    		}
    	}
    
    	return nil
    }
  8. cherrymui commented on Feb 21, 2017

    @cherrymui
    Member

    @funny-falcon Thanks for the repro! However, the related values are not touched in the writebarrier pass, and they are in the correct order at that point. Later the tighten pass got something wrong. So it's a different bug. I'll take a look.

  9. funny-falcon commented on Feb 21, 2017

    @funny-falcon
    Contributor

    @cherrymui panic("") could be changed to any non-empty line: ixw = 0, return nil or break - all still trigger error. But removing that line makes it compileable.

  10. cherrymui commented on Feb 21, 2017

    @cherrymui
    Member

    @funny-falcon, I filed issue #19217, since it is a different bug, and even apply to Go 1.8.

  11. funny-falcon commented on Feb 21, 2017

    @funny-falcon
    Contributor

    @cherrymui, thank you

  12. locked and limited conversation to collaborators on Feb 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions