Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/vet: false positive for uint128 ([2]uint64) #46843

Closed
zhangyunhao116 opened this issue Jun 21, 2021 · 4 comments
Closed

cmd/vet: false positive for uint128 ([2]uint64) #46843

zhangyunhao116 opened this issue Jun 21, 2021 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@zhangyunhao116
Copy link
Contributor

zhangyunhao116 commented Jun 21, 2021

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

$ go version
go version go1.16.5 linux/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="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/zyh/.cache/go-build"
GOENV="/home/zyh/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/zyh/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/zyh/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/zyh/GitHub/lscqtest/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2984921841=/tmp/go-build -gno-record-gcc-switches"

What did you do?

go vet these files

asm.go Content
// +build amd64,!gccgo,!appengine

package lscq

import "unsafe"

type uint128 [2]uint64

func compareAndSwapUint128(addr *uint128, old, new uint128) (swapped bool)

asm_amd64.s Content
// +build amd64,!gccgo,!appengine

#include "textflag.h"

TEXT ·compareAndSwapUint128(SB),NOSPLIT,$0
MOVQ addr+0(FP), R8
MOVQ old+8(FP), AX
MOVQ old+16(FP), DX
MOVQ new+24(FP), BX
MOVQ new+32(FP), CX
LOCK
CMPXCHG16B (R8)
SETEQ swapped+40(FP)
RET

What did you expect to see?

Nothing will happen.

What did you see instead?

./asm_amd64.s:7:1: [amd64] compareAndSwapUint128: invalid MOVQ of old+8(FP); github.com/zhangyunhao116/lscqtest.uint128 is 16-byte value
./asm_amd64.s:8:1: [amd64] compareAndSwapUint128: invalid offset old+16(FP); expected old+8(FP)
./asm_amd64.s:9:1: [amd64] compareAndSwapUint128: invalid MOVQ of new+24(FP); github.com/zhangyunhao116/lscqtest.uint128 is 16-byte value
./asm_amd64.s:10:1: [amd64] compareAndSwapUint128: invalid offset new+32(FP); expected new+24(FP)
./asm_amd64.s:24:1: [amd64] loadUint128: invalid MOVQ of val+8(FP); github.com/zhangyunhao116/lscqtest.uint128 is 16-byte value
./asm_amd64.s:25:1: [amd64] loadUint128: invalid offset val+16(FP); expected val+8(FP)
@zhangyunhao116
Copy link
Contributor Author

Some hints:
These errors come from
https://github.com/golang/tools/blob/master/go/analysis/passes/asmdecl/asmdecl.go#L782
https://github.com/golang/tools/blob/master/go/analysis/passes/asmdecl/asmdecl.go#L800

Looks like go vet should allow a single instruction to load each part of an array?

@seankhliao
Copy link
Member

cc @matloob

@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 21, 2021
@josharian
Copy link
Contributor

Try e.g.

MOVQ new_0+24(FP), BX
MOVQ new_1+32(FP), CX

That is, use underscores to refer to components of a composite type.

@zhangyunhao116
Copy link
Contributor Author

@josharian It works, thanks a lot!

Try e.g.

MOVQ new_0+24(FP), BX
MOVQ new_1+32(FP), CX

That is, use underscores to refer to components of a composite type.

@golang golang locked and limited conversation to collaborators Jun 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants