Skip to content

cmd/compile: generates invalid instruction when using bit shifts on amd64 #38746

@kynrai

Description

@kynrai

What version of Go are you using (go version)?

$ go version
go version go1.14.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/steve/go/bin"
GOCACHE="/Users/steve/Library/Caches/go-build"
GOENV="/Users/steve/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/steve/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.2_1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.2_1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/steve/Projects/kynrai/invalid_instruction/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sm/hgxsvgvx3h93cb_0cwyj39g80000gn/T/go-build850937365=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Using bit shifts to store data when a sequence of code causes a invalid instruction error:
invalid instruction: 00080 (invalid_test.go:22) ANDQ $9223372034707292159, CX

I have minimised the code example to the smallest amount of code that will reproduce the error.

package invalid

import (
	"testing"
)

type ValuesMask uint64

func (v *ValuesMask) PrintBits() {
	for i := 0; i < 64; i++ {
	}
}

func TestMask(t *testing.T) {
	v := ValuesMask(0)
	v.PrintBits()

	v &^= (1 << 31)

	v |= 1 << 63

	v &^= (1 << 63)
}

What did you expect to see?

No error? or a pointer related error at worst

What did you see instead?

invalid instruction: 00080 (/Users/steve/Projects/kynrai/invalid_instruction/invalid_test.go:22) ANDQ $9223372034707292159, CX

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.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions