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: reports sync.Mutex copy in unsafe.Sizeof #21800

Closed
achille-roussel opened this issue Sep 8, 2017 · 1 comment
Closed

cmd/vet: reports sync.Mutex copy in unsafe.Sizeof #21800

achille-roussel opened this issue Sep 8, 2017 · 1 comment
Milestone

Comments

@achille-roussel
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/achilleroussel/dev"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0p/tfjq063j4hdcjnm0_9qb4bww0000gn/T/go-build312584611=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

go vet gives a false positive when using unsafe.Sizeof on an expression that would copy a sync.Mutex, here's a minimal example:

package main

import (
	"sync"
	"unsafe"
)

func main() {
	mu := sync.Mutex{}
	println(unsafe.Sizeof(mu))
}
$ go vet ./test.go
test.go:10: call of unsafe.Sizeof copies lock value: sync.Mutex
exit status 1

What did you expect to see?

I would expect go vet to not report unsafe.Sizeof as an unsafe operation since it's resolved at compile time and therefore doesn't cause a copy. It should also return 0 in the program given as example.

What did you see instead?

go vet returns 1 to indicate a failure because it misinterpreted the call to unsafe.Sizeof as making a copy of a mutex.

@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Sep 8, 2017
@gopherbot
Copy link

Change https://golang.org/cl/66210 mentions this issue: cmd/vet: fix copylocks false positive on unsafe.Sizeof(mutex)

@golang golang locked and limited conversation to collaborators Oct 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants