Skip to content

cmd/compile: arm64 build fails with: constrained unpredictable behavior #75063

Closed

Description

@stapelberg

Go version

go version go1.26-devel_77f911e31c Fri Aug 15 18:10:28 2025 -0700 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/usr/local/google/home/stapelberg/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/usr/local/google/home/stapelberg/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3818096045=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/usr/local/google/home/stapelberg/src/arm-unpredictable/go.mod'
GOMODCACHE='/usr/local/google/home/stapelberg/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/usr/local/google/home/stapelberg/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/google/home/stapelberg/upstream-go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/usr/local/google/home/stapelberg/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/google/home/stapelberg/upstream-go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.26-devel_77f911e31c Fri Aug 15 18:10:28 2025 -0700'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

  1. go mod init repro
  2. Write the following repro.go file:
package reorder

type Element struct {
	A     string
	B     string
	C     string
	D     string
	E     string
	Text  []string
	List  []string
	Child Elements
	F     string
	G     bool
	H     bool
	I     string
}

type Elements []Element

func DoesNotCompile(ve Elements) Elements {
	aa := Elements{}
	bb := Elements{}
	cc := Elements{}
	dd := Elements{}
	ee := Elements{}
	ff := Elements{}
	gg := Elements{}
	hh := Elements{}
	ii := Elements{}

	if len(ve) != 1 {
		return ve
	}
	for _, e := range ve[0].Child {
		if len(e.Text) == 1 && (e.Text[0] == "xx") {
			ee = append(ee, e)
		} else if len(e.Text) == 1 && e.Text[0] == "yy" {
			for _, c := range e.Child {
				if len(c.Text) == 1 && c.Text[0] == "zz" {
					ii = append(ii, c)
				} else {
					hh = append(hh, c)
				}
			}
			ii = append(ii, hh...)
			e.Child = ii
			gg = append(gg, e)
		} else if len(e.Text) == 1 && e.Text[0] == "tt" {
			for _, entry := range e.Child {
				for _, c := range entry.Child {
					if len(c.Text) == 1 && c.Text[0] == "ee" {
						cc = append(cc, c)
					} else {
						dd = append(dd, c)
					}
				}
				cc = append(cc, dd...)
				entry.Child = cc
				bb = append(bb, entry)
				cc, dd = Elements{}, Elements{}
			}
			e.Child = bb
			aa = append(aa, e)
		} else {
			ff = append(ff, e)
		}
	}
	return ve
}
  1. Compile this package using: GOARCH=arm64 go build

What did you see happen?

# repro
./repro.go:68:2: constrained unpredictable behavior: 01460 (/usr/local/google/home/stapelberg/src/arm-unpredictable/repro.go:49)	LDP.P	16(R24), (R24, R25)
./repro.go:68:2: constrained unpredictable behavior: 01468 (/usr/local/google/home/stapelberg/src/arm-unpredictable/repro.go:49)	LDP.P	16(R24), (R24, R25)
./repro.go:68:2: constrained unpredictable behavior: 01476 (/usr/local/google/home/stapelberg/src/arm-unpredictable/repro.go:49)	LDP.P	16(R24), (R24, R25)
./repro.go:68:2: constrained unpredictable behavior: 01484 (/usr/local/google/home/stapelberg/src/arm-unpredictable/repro.go:49)	LDP.P	16(R24), (R24, R25)
./repro.go:68:2: constrained unpredictable behavior: 03220 (/usr/local/google/home/stapelberg/src/arm-unpredictable/repro.go:38)	LDP.P	16(R24), (R24, R25)
./repro.go:68:2: constrained unpredictable behavior: 03228 (/usr/local/google/home/stapelberg/src/arm-unpredictable/repro.go:38)	LDP.P	16(R24), (R24, R25)
./repro.go:68:2: constrained unpredictable behavior: 03236 (/usr/local/google/home/stapelberg/src/arm-unpredictable/repro.go:38)	LDP.P	16(R24), (R24, R25)
./repro.go:68:2: constrained unpredictable behavior: 03244 (/usr/local/google/home/stapelberg/src/arm-unpredictable/repro.go:38)	LDP.P	16(R24), (R24, R25)

What did you expect to see?

Commit bca3e98 is the last working commit.

Commit 15d6dbc (“cmd/compile: use generated loops instead of DUFFCOPY on arm64”) is the first broken commit.

Activity

  1. added
    BugReportIssues describing a possible bug in the Go implementation.
    on Aug 18, 2025
  2. randall77 commented on Aug 18, 2025

    @randall77
    Contributor

    Strange. Must be something wrong with regalloc. This instruction specifically asks for the input not to be in R24.

    After regalloc:

    v353 (49) = Copy <unsafe.Pointer> v602 : R24
    v607 (49) = LoweredMoveLoop <mem> [192] v562 v353 v605
    

    But LoweredMoveLoop's spec is:

    				inputs:       []regMask{gp &^ r23to25, gp &^ r23to25},
    

    I will investigate.

  3. gopherbot commented on Aug 18, 2025

    @gopherbot
    Contributor

    Change https://go.dev/cl/697015 mentions this issue: cmd/compile: ensure we use allowed registers for input-clobbering instructions

  4. locked and limited conversation to collaborators on Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.FrozenDueToAgecompiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions