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: bad live variable at entry (part 3) #32454

Closed
ALTree opened this issue Jun 5, 2019 · 2 comments

Comments

@ALTree
Copy link
Member

commented Jun 5, 2019

$ gotip version
go version devel +9ab9ca27bb Wed Jun 5 16:33:20 2019 +0000 linux/amd64

This is a follow-up to #29218. On the CL that fixed that one, @josharian wrote:

It is not clear that this fixes every variant of #29218,
but it is a reasonable standalone change.
And code like #29218 is rare and fundamentally buggy,
so we can handle new instances if/when they actually occur.

This is a variant of the reproducer on #29218 that still crashes the tip compiler. The program:

package p

type T struct {
	s string
	f float64
}

func f() {
	var f float64
	var st T
	for {
		switch &st.f {
		case &f:
			f = 1
		}
	}
}

The error is the same as in #29218:

$ gotip build crash.go 

# command-line-arguments
<autogenerated>:1: internal compiler error: bad live variable at entry of f: st (type T)

goroutine 37 [running]:
runtime/debug.Stack(0xfd83c0, 0xc000098008, 0x0)
	/home/alberto/go/src/runtime/debug/stack.go:24 +0x9d
cmd/compile/internal/gc.Fatalf(0xe498c8, 0x24, 0xc0004f9758, 0x2, 0x2)
	/home/alberto/go/src/cmd/compile/internal/gc/subr.go:188 +0x291
cmd/compile/internal/gc.(*Liveness).epilogue(0xc0002c8500)
	/home/alberto/go/src/cmd/compile/internal/gc/plive.go:1004 +0xc0e
cmd/compile/internal/gc.liveness(0xc0004d6120, 0xc0004ce420, 0xc0002c6150, 0x0, 0xe3a97a, 0xd)
	/home/alberto/go/src/cmd/compile/internal/gc/plive.go:1399 +0xc4
cmd/compile/internal/gc.genssa(0xc0004ce420, 0xc0002c6150)
	/home/alberto/go/src/cmd/compile/internal/gc/ssa.go:5286 +0x92
cmd/compile/internal/gc.compileSSA(0xc0002c4160, 0x3)
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:308 +0x3c2
cmd/compile/internal/gc.compileFunctions.func2(0xc0004c34a0, 0xc0004a4230, 0x3)
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:363 +0x49
created by cmd/compile/internal/gc.compileFunctions
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:361 +0x128

cc @randall77

@ALTree ALTree added this to the Go1.14 milestone Jun 5, 2019
@josharian

This comment has been minimized.

Copy link
Contributor

commented Jun 6, 2019

Continuing the tradition of fixing these bugs indirectly, I have a CL coming shortly that fixes this, but not for any deep reason, and which is independently justifiable. Thanks for continuing to file these, @ALTree; they're productive sources of optimizations. :)

@gopherbot

This comment has been minimized.

Copy link

commented Jun 6, 2019

Change https://golang.org/cl/180940 mentions this issue: cmd/compile: optimize more pointer comparisons

@gopherbot gopherbot closed this in b8cbcac Aug 29, 2019
tomocy added a commit to tomocy/go that referenced this issue Sep 1, 2019
The existing pointer comparison optimizations
don't include pointer arithmetic. Add them.

These rules trigger a few times in std cmd, while compiling:

time.Duration.String
cmd/go/internal/tlog.NodeHash
crypto/tls.ticketKeyFromBytes (3 times)
crypto/elliptic.(*p256Point).p256ScalarMult (15 times!)
crypto/elliptic.initTable

These weird comparisons occur when using the copy builtin,
which does a pointer comparison between src and dst.

This also happens to fix golang#32454, by optimizing enough
early on that all values can be eliminated.

Fixes golang#32454

Change-Id: I799d45743350bddd15a295dc1e12f8d03c11d1c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/180940
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
t4n6a1ka added a commit to t4n6a1ka/go that referenced this issue Sep 5, 2019
The existing pointer comparison optimizations
don't include pointer arithmetic. Add them.

These rules trigger a few times in std cmd, while compiling:

time.Duration.String
cmd/go/internal/tlog.NodeHash
crypto/tls.ticketKeyFromBytes (3 times)
crypto/elliptic.(*p256Point).p256ScalarMult (15 times!)
crypto/elliptic.initTable

These weird comparisons occur when using the copy builtin,
which does a pointer comparison between src and dst.

This also happens to fix golang#32454, by optimizing enough
early on that all values can be eliminated.

Fixes golang#32454

Change-Id: I799d45743350bddd15a295dc1e12f8d03c11d1c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/180940
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
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
Projects
None yet
3 participants
You can’t perform that action at this time.