Skip to content

cmd/vet: noCopy is not detected on append #71929

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

Closed
mneverov opened this issue Feb 24, 2025 · 2 comments
Closed

cmd/vet: noCopy is not detected on append #71929

mneverov opened this issue Feb 24, 2025 · 2 comments
Labels
BugReport Issues describing a possible bug in the Go implementation.

Comments

@mneverov
Copy link
Contributor

Go version

go version go1.24.0 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/mneverov/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/mneverov/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/home/mneverov/tmp/go-build1453477970=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/mneverov/go/src/github.com/mneverov/test/go.mod'
GOMODCACHE='/home/mneverov/go/pkg/mod'
GOOS='linux'
GOPATH='/home/mneverov/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/mneverov/.config/go/telemetry'
GOTMPDIR='/home/mneverov/tmp'
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.0'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

func main() {
	s := make([]sync.Mutex, 1, 1)
	s[0] = sync.Mutex{}

	var s1 []sync.Mutex
	for range 1 {
		s1 = append(s, sync.Mutex{})
	}

	s[0].Lock()
	s1[0].Lock()
	fmt.Println("not ok")
}

link.

go vet does not complain about copying the slice during append. Same when a map grows.

What did you see happen?

go vet does not complain about mutexes being copied

What did you expect to see?

call of append copies lock value: sync.Mutex

@seankhliao
Copy link
Member

This can't be accurate accurate enough for vet: it's safe to use if the capacity is enough for append without growing the backing array.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2025
@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation.
Projects
None yet
Development

No branches or pull requests

3 participants