]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: add test of maps with keys larger than key size
authorMichael Pratt <mpratt@google.com>
Thu, 21 Nov 2024 18:56:57 +0000 (13:56 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 21 Nov 2024 23:02:11 +0000 (23:02 +0000)
This finds the bug fixed in CL 630279.

reflect mutates the SwissMapType of a map[unsafe.Pointer]unsafe.Pointer,
which happened to already have the correct GroupSize for all of the maps
used in the reflect tests.

For #54766.

Change-Id: If4428e1e799598e7512edceb3cefb2ad00cfa712
Reviewed-on: https://go-review.googlesource.com/c/go/+/630676
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>

src/reflect/all_test.go

index 687bbfc1075d718aa83d01f77fd96fe90a55bce3..b2f70c13697735b57db701ab25ba305f53d2cca1 100644 (file)
@@ -6309,6 +6309,32 @@ func TestMapOfGCKeys(t *testing.T) {
        }
 }
 
+// Test assignment and access to a map with keys larger than word size.
+func TestMapOfGCBigKey(t *testing.T) {
+       type KV struct {
+               i int64
+               j int64
+       }
+
+       kvTyp := TypeFor[KV]()
+       mt := MapOf(kvTyp, kvTyp)
+
+       const n = 100
+       m := MakeMap(mt)
+       for i := 0; i < n; i++ {
+               kv := KV{int64(i), int64(i+1)}
+               m.SetMapIndex(ValueOf(kv), ValueOf(kv))
+       }
+
+       for i := 0; i < n; i++ {
+               kv := KV{int64(i), int64(i+1)}
+               elem := m.MapIndex(ValueOf(kv)).Interface().(KV)
+               if elem != kv {
+                       t.Errorf("lost m[%v] = %v, want %v", kv, elem, kv)
+               }
+       }
+}
+
 func TestMapOfGCValues(t *testing.T) {
        type T *uintptr
        tt := TypeOf(T(nil))