-
Notifications
You must be signed in to change notification settings - Fork 18k
maps: maps.Clone reference semantics when cloning a map with large value types #64474
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
Comments
@gopherbot, please backport to Go 1.21. This appears to cause subtle aliasing bugs in cloned maps. |
Backport issue(s) opened: #64475 (for 1.21). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
(I made a minor correction to the original report, changing the expectation to |
I can confirm this behavior changed after CL 471400 moved the Clone implementation to the runtime. |
The bug triggers this branch of mapclone2 https://go.googlesource.com/go/+/refs/heads/master/src/runtime/map.go#1512 if src.B == 0 {
dst.buckets = newobject(t.Bucket)
dst.count = src.count
typedmemmove(t.Bucket, dst.buckets, src.buckets)
return dst
} |
Change https://go.dev/cl/546515 mentions this issue: |
Make sure to alloc+copy large keys and values instead of aliasing them, when they might be updated by a future assignment. Fixes golang#64474 Change-Id: Ie2226a81cf3897e4e2ee24472f2966d397ace53f Reviewed-on: https://go-review.googlesource.com/c/go/+/546515 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
Go version
go version go1.21.4 linux/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
https://go.dev/play/p/vkz2JOzn6zV
Possibly related to https://go-review.googlesource.com/c/go/+/471400
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: