Skip to content

cmd/compile: miscompile of shift on GOOS=arm  #64715

@thanm

Description

@thanm

Go version

go version devel go1.22-f2d243db8f Wed Dec 13 16:20:09 2023 +0000 linux/amd64

What operating system and processor architecture are you using (go env)?

linux/arm

What did you do?

NB: filing this issue on behalf of Jan Mercl, who discovered and reported the problem here

Run this program on a GOOS=linux GOARCH=arm machine:

package main

func boolInt32(b bool) int32 {
	if b {
		return 1
	}

	return 0
}

func f(left uint16, right int32) (r uint16) {
	return left >> right
}

var n = uint16(65535)

func main() {
	println(f(n, boolInt32(int64(n^n) > 1)))
}

What did you expect to see?

Expected:

$ go run prog.go
65535
$

What did you see instead?

Got instead:

$ go run prog.go
0
$

Also worth noting that building with -gcflags="-l -N" makes the problem go away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.arch-armIssues solely affecting the 32-bit arm architecture.compiler/runtimeIssues related to the Go compiler and/or runtime.release-blocker

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions