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: not lowered: v94, Int64Make INT64 INT32 UINT32 #21517

Closed
dvyukov opened this issue Aug 18, 2017 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Aug 18, 2017

go version devel +59413d34c9 Fri Aug 18 06:59:48 2017 +0000 linux/amd64

Checkout github.com/google/syzkaller on 172189e9551b768d48c6d5c038fbf3d5cd88aa8e, run:

$ GOARCH=arm go install github.com/google/syzkaller/pkg/ifuzz

produces:

# github.com/google/syzkaller/pkg/ifuzz
pkg/ifuzz/ifuzz.go:254:2: internal compiler error: not lowered: v94, Int64Make INT64 INT32 UINT32

goroutine 69 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
	go/src/runtime/debug/stack.go:24 +0xa7
cmd/compile/internal/gc.Fatalf(0xb5bd5d, 0x2, 0xc4240db230, 0x1, 0x1)
	go/src/cmd/compile/internal/gc/subr.go:181 +0x1f4
cmd/compile/internal/gc.(*ssafn).Fatalf(0xc4241d1500, 0xfe0200000012, 0xb5bd5d, 0x2, 0xc4240db230, 0x1, 0x1)
	go/src/cmd/compile/internal/gc/ssa.go:5093 +0x67
cmd/compile/internal/ssa.(*Func).Fatalf(0xc4241eaa00, 0xb5bd5d, 0x2, 0xc4240db230, 0x1, 0x1)
	go/src/cmd/compile/internal/ssa/func.go:496 +0x78
cmd/compile/internal/ssa.checkLower(0xc4241eaa00)
	go/src/cmd/compile/internal/ssa/lower.go:36 +0x35c
cmd/compile/internal/ssa.Compile(0xc4241eaa00)
	go/src/cmd/compile/internal/ssa/compile.go:70 +0x2bb
cmd/compile/internal/gc.buildssa(0xc420534f20, 0x2, 0x0)
	go/src/cmd/compile/internal/gc/ssa.go:216 +0xd39
cmd/compile/internal/gc.compileSSA(0xc420534f20, 0x2)
	go/src/cmd/compile/internal/gc/pgen.go:241 +0x3c
cmd/compile/internal/gc.compileFunctions.func2(0xc4205578c0, 0xc420d6a430, 0x2)
	go/src/cmd/compile/internal/gc/pgen.go:290 +0x49
created by cmd/compile/internal/gc.compileFunctions
	go/src/cmd/compile/internal/gc/pgen.go:288 +0x10e

The code is simply:

func generateInt(cfg *Config, r *rand.Rand, size int) uint64 {
        if size != 1 && size != 2 && size != 4 && size != 8 {  // LINE 254
@ALTree
Copy link
Member

ALTree commented Aug 18, 2017

That line indication is misleading, it's not the if that triggers the crash. Here's a small reproducer:

package p

//go:noinline
func f() uint64 { return 0 }

func g() uint64 {
	return f() % (1 << 63)
}

Gives:

$ gotip version
go version devel +66a1d37bf7 Fri Aug 18 09:28:16 2017 +0000 linux/amd64

$ GOARCH=arm gotip build prova.go
# command-line-arguments
./prova.go:7:2: internal compiler error: not lowered: v8, Int64Make UINT64 UINT32 UINT32

goroutine 34 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
	/home/alberto/go/src/runtime/debug/stack.go:24 +0xa7
cmd/compile/internal/gc.Fatalf(0xb5bd5d, 0x2, 0xc4204be0e0, 0x1, 0x1)
	/home/alberto/go/src/cmd/compile/internal/gc/subr.go:181 +0x1f4
cmd/compile/internal/gc.(*ssafn).Fatalf(0xc4204b2000, 0x70200000002, 0xb5bd5d, 0x2, 0xc4204be0e0, 0x1, 0x1)
	/home/alberto/go/src/cmd/compile/internal/gc/ssa.go:5093 +0x67
cmd/compile/internal/ssa.(*Func).Fatalf(0xc4204b4000, 0xb5bd5d, 0x2, 0xc4204be0e0, 0x1, 0x1)
	/home/alberto/go/src/cmd/compile/internal/ssa/func.go:496 +0x78
cmd/compile/internal/ssa.checkLower(0xc4204b4000)
	/home/alberto/go/src/cmd/compile/internal/ssa/lower.go:36 +0x35c
cmd/compile/internal/ssa.Compile(0xc4204b4000)
	/home/alberto/go/src/cmd/compile/internal/ssa/compile.go:70 +0x2bb
cmd/compile/internal/gc.buildssa(0xc420318160, 0x1, 0x0)
	/home/alberto/go/src/cmd/compile/internal/gc/ssa.go:216 +0xd39
cmd/compile/internal/gc.compileSSA(0xc420318160, 0x1)
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:241 +0x3c
cmd/compile/internal/gc.compileFunctions.func2(0xc42049c000, 0xc420494020, 0x1)
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:290 +0x49
created by cmd/compile/internal/gc.compileFunctions
	/home/alberto/go/src/cmd/compile/internal/gc/pgen.go:288 +0x10e

I can reproduce this with tip and with go1.9rc2. Not with go1.8.3

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 18, 2017
@cherrymui
Copy link
Member

It is this code

v = uint64(r.Int63()) % (1 << 63)

that causes problem.

Normally 64-bit div/mod is turned into runtime calls on 32-bit arch, but the front end leaves power-of-two constant division and hopes the SSA backend turns into a shift or AND. The SSA rule is

(Mod64u <t> n (Const64 [c])) && isPowerOfTwo(c)            -> (And64 n (Const64 <t> [c-1]))

But isPowerOfTwo returns true only for possitive int64

func isPowerOfTwo(n int64) bool {
	return n > 0 && n&(n-1) == 0
}

In this case, however, c==1<<63, doesn't trigger the rule...

@cherrymui
Copy link
Member

Also reproducible with Go 1.9rc2, but not with Go 1.8. Mark as Go 1.9 issue.

@cherrymui cherrymui added this to the Go1.9 milestone Aug 18, 2017
@gopherbot
Copy link

Change https://golang.org/cl/56890 mentions this issue: cmd/compile: add rules handling unsigned div/mod by constant 1<<63

@ALTree ALTree added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 18, 2017
@gopherbot
Copy link

Change https://golang.org/cl/57070 mentions this issue: [release-branch.go1.9] cmd/compile: add rules handling unsigned div/mod by constant 1<<63

gopherbot pushed a commit that referenced this issue Aug 18, 2017
…od by constant 1<<63

Cherry-pick CL 56890.

Normally 64-bit div/mod is turned into runtime calls on 32-bit
arch, but the front end leaves power-of-two constant division
and hopes the SSA backend turns into a shift or AND. The SSA rule is

(Mod64u <t> n (Const64 [c])) && isPowerOfTwo(c) -> (And64 n (Const64 <t> [c-1]))

But isPowerOfTwo returns true only for positive int64, which leaves
out 1<<63 unhandled. Add a special case for 1<<63.

Fixes #21517.

Change-Id: Ic91f86fd5e035a8bb64b937c15cb1c38fec917d6
Reviewed-on: https://go-review.googlesource.com/57070
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Aug 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants