Skip to content

cmd/compile: Rsh...x32 can get confused by garbage in the upper half of the register #79886

Closed

Description

@Jorropo

Go version

go version go1.27-devel_35e6f583ff Fri Jun 5 19:04:53 2026 -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='0'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/home/hugo/go/bin'
GOCACHE='/tmp/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/hugo/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build54446344=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/hugo/k/go/src/go.mod'
GOMODCACHE='/home/hugo/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPACKAGESDRIVER=''
GOPATH='/home/hugo/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/hugo/k/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/hugo/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/home/hugo/k/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.27-devel_35e6f583ff Fri Jun 5 19:04:53 2026 -0700'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Run:

package main

import (
	"fmt"
	"os"
)

//go:noinline
func shifted(x int64, y uint64) int64 {
	return x >> uint32(y)
}

func main() {
	x := int64(-0x4000000000000000)
	got := shifted(x, ^uint64(0)&^(1<<32-2))
	want := x >> 1
	if got != want {
		panic(fmt.Sprintf("want %d; got %d", want, got))
	}
}

What did you see happen?

It panics.

What did you expect to see?

It does not panic.

Activity

  1. Jorropo commented on Jun 7, 2026

    @Jorropo
    MemberAuthor

    Tentatively putting release blocker as it's a new regression in 1.27


    Found in https://cls-are-slow.exe.xyz/bughunt/view?name=arm64-rsh64x32-truncated-count-miscompile.md&back=%2Fbughunt%3Fq%3Dtag%253Acc%253Ajorropo%2Bmeta%253Adefault


    The bug is a naive copy paste mistake in arm64's rewrite rules.

  2. gopherbot commented on Jun 7, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/787920 mentions this issue: cmd/compile: fix misscompilation of Rsh with 32bits rhs on arm64

  3. added
    FixPendingIssues that have a fix which has not yet been reviewed or submitted.
    on Jun 7, 2026
  4. added this to the Go1.27 milestone on Jun 10, 2026
  5. added a commit that references this issue on Jun 11, 2026
    f2f369d
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

    FixPendingIssues that have a fix which has not yet been reviewed or submitted.compiler/runtimeIssues related to the Go compiler and/or runtime.release-blocker

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions