Skip to content

cmd/compile: internal compiler error: ZeroLoop too small #81242

Closed

Description

@YuanchengJiang

The following code:

package main
import (
	"fmt"
	"runtime"
	"unsafe"
)
var callback func()
type T struct{
	big2
}
//go:uintptrescapes
func (T) Mv(ptrs ...uintptr) { callback() }
var tests = []func(ptr unsafe.Pointer){
	func(ptr unsafe.Pointer) { T{}.Mv(uintptr(ptr)) },
}
func main() {
	for i, test := range tests {
		finalized := false
		ptr := new([64]byte)
		runtime.SetFinalizer(ptr, func(*[64]byte) {
		})
		callback = func() {
			if finalized {
				fmt.Printf("test #%d failed\n", i)
			}
		}
		test(unsafe.Pointer(ptr))
	}
}
type big1 struct {
	w [1<<30 - 1]uint32
}
type big2 struct {
	d [1<<29 - 1]uint64
}
func loadLargeOffset(sw *big1, sd *big2) (uint32, uint64) {
	a3 := sw.w[1<<10]
	b3 := sw.w[1<<16]
	c3 := sw.w[1<<28]
	d3 := sw.w[1<<29]
	a4 := sd.d[1<<10]
	b4 := sd.d[1<<16]
	c4 := sd.d[1<<27]
	d4 := sd.d[1<<28]
	return a3 + b3 + c3 + d3, a4 + b4 + c4 + d4
}
type big1_bd84f3a struct {
	w [1<<30 - 1]uint32
}
type big2_bd84f3a struct {
	d [1<<29 - 1]uint64
}
func loadLargeOffset_bd84f3a(sw *big1_bd84f3a, sd *big2_bd84f3a) (uint32, uint64) {
	a3 := sw.w[1<<10]
	b3 := sw.w[1<<16]
	c3 := sw.w[1<<28]
	d3 := sw.w[1<<29]
	a4 := sd.d[1<<10]
	b4 := sd.d[1<<16]
	c4 := sd.d[1<<27]
	d4 := sd.d[1<<28]
	return a3 + b3 + c3 + d3, a4 + b4 + c4 + d4
}

Resulted in this output:

# fflreduce
./main.go:14:35: internal compiler error: 'init.func1': ZeroLoop too small:-8, expect:192

goroutine 23 [running]:
runtime/debug.Stack()
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/runtime/debug/stack.go:26 +0x5e
cmd/compile/internal/base.FatalfAt({0xcf74b2d0?, 0x11b9?}, {0x11b9cf74b270, 0x26}, {0x11b9cf67db90, 0x3, 0x3})
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/base/print.go:232 +0x18b
cmd/compile/internal/base.Fatalf(...)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/base/print.go:197
cmd/compile/internal/ssagen.(*ssafn).Fatalf(0x9661ca?, {0xcf9800a0?, 0x11b9?}, {0x106f576, 0x20}, {0x11b9cf5f3ea0, 0x2, 0x8?})
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/ssagen/ssa.go:8056 +0x185
cmd/compile/internal/ssa.(*Func).FatalfWithPos(0x11b9cf726000, {0x19b4ae0?, 0x0?}, {0x106f576, 0x20}, {0x11b9cf5f3ea0, 0x2, 0x2})
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/ssa/func.go:801 +0x190
cmd/compile/internal/ssa.(*Value).Fatalf(...)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/ssa/value.go:559
cmd/compile/internal/riscv64.ssaGenValue(0x11b9cf9800a0, 0x11b9cebf4e30)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/riscv64/ssa.go:818 +0xb09
cmd/compile/internal/ssagen.genssa({0x1a73ba8, 0x0}, 0x11b9cf726000, 0x11b9cf65daa0)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/ssagen/ssa.go:7181 +0x19ac
cmd/compile/internal/ssagen.Compile({0x1a71270, 0x1d10160}, 0x11b9ce62c8c0, 0xd, 0x0?)
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/ssagen/pgen.go:316 +0x513
cmd/compile/internal/gc.compileFunctions.func2()
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/cmd/compile/internal/gc/compile.go:174 +0x1b9
sync.(*WaitGroup).Go.func1()
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/sync/waitgroup.go:258 +0x4a
created by sync.(*WaitGroup).Go in goroutine 1
	/home/fuzz/WorkSpace/fusion-fuzz/projects/go/go-src/src/sync/waitgroup.go:238 +0x7d


To reproduce:

GOOS=linux GOARCH=riscv64 go build .

Compiler version:

go version go1.28-devel_603439a1 Fri Aug 28 21:44:26 2026 -0700 linux/amd64

Commit:

603439a1c6f2d37c7f02e246342847056ed04c21

Build configuration:

cd src && ./make.bash (GOROOT_BOOTSTRAP=go1.26.0)

Operating System:

Ubuntu 22.04 Host, Docker fusion-fuzz-go:latest

This bug was found by fusion-fuzz

Activity

  1. YuanchengJiang commented on Aug 31, 2026

    @YuanchengJiang
    Author

    reduced to:

    package main
    
    type T [1<<29 - 1]uint64
    
    //go:uintptrescapes
    func Mv(t T, p uintptr) {}
    
    func main() { Mv(T{}, 0) }
  2. dr2chase commented on Aug 31, 2026

    @dr2chase
    Contributor

    @golang/riscv64

  3. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Aug 31, 2026
  4. thepudds commented on Aug 31, 2026

    @thepudds
    Member

    FWIW, this also seems not new to Go 1.27.

    Currently running a bisect, and the remaining window is in early September, 2025.

  5. thepudds commented on Aug 31, 2026

    @thepudds
    Member

    Bisect seemed to land on 879ff73, which is one commit off from where the #81240 bisect landed:

      first BAD:   879ff736d3 | 2025-09-10 02:41 | cmd/compile: use generated loops instead of DUFFZERO on riscv64
      GOOD parent: 77643dc63f | 2025-09-10 02:41 | cmd/compile: simplify zerorange on riscv64
    

    CC @mengzhuo

  6. HeliC829 commented on Aug 31, 2026

    @HeliC829
    Contributor

    FWIW, this also seems not new to Go 1.27.

    Currently running a bisect, and the remaining window is in early September, 2025.

    It looks like the log “ZeroLoop too small:” is coming from https://go-review.googlesource.com/c/go/+/699635

  7. changed the title [-]ICE: ZeroLoop too small[/-] [+]cmd/compile: internal compiler error: ZeroLoop too small[/+] on Aug 31, 2026
  8. gopherbot commented on Aug 31, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/824984 mentions this issue: cmd/compile: fix large riscv64 move/zero

  9. added a commit that references this issue on Sep 1, 2026
    5c1ad45
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

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions