Skip to content

cmd/compile: unexpected amd64 error #32701

Closed
@ghost

Description

Some simple code went wrong (only) on amd64.

The following go code

func main() {
	b := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
	temp := make([]byte, 4)
	for i := int64(0);i<4; i ++ {
		temp[0] = b[i*4 + 2]
		temp[1] = b[i*4 + 3]
		temp[2] = b[i*4 + 0]
		temp[3] = b[i*4 + 1]
		n := binary.BigEndian.Uint32(temp)
		fmt.Printf("%x\n", n)
	}
}

is expected to print

3040102
7080506
b0c090a
f100d0e

That is true on arm/arm64/386, but false on amd64.

apuser@tj07598pcu:~/Desktop$ GOARCH=arm go run main.go 
3040102
7080506
b0c090a
f100d0e
apuser@tj07598pcu:~/Desktop$ GOARCH=386 go run main.go 
3040102
7080506
b0c090a
f100d0e
apuser@tj07598pcu:~/Desktop$ GOARCH=amd64 go run main.go 
3040000
7080102
b0c0506
f10090a
apuser@tj07598pcu:~/Desktop$ GOARCH=arm64 go run main.go 
3040102
7080506
b0c090a	
f100d0e
apuser@tj07598pcu:~/Desktop$ go version
go version devel +71a6a44428 Wed Jun 19 23:17:25 2019 +0000 linux/amd64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions