Skip to content

Commit 0dafae1

Browse files
prattmicgopherbot
authored andcommitted
reflect: add test of maps with keys larger than key size
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 <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Michael Pratt <[email protected]>
1 parent f0b0109 commit 0dafae1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/reflect/all_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6309,6 +6309,32 @@ func TestMapOfGCKeys(t *testing.T) {
63096309
}
63106310
}
63116311

6312+
// Test assignment and access to a map with keys larger than word size.
6313+
func TestMapOfGCBigKey(t *testing.T) {
6314+
type KV struct {
6315+
i int64
6316+
j int64
6317+
}
6318+
6319+
kvTyp := TypeFor[KV]()
6320+
mt := MapOf(kvTyp, kvTyp)
6321+
6322+
const n = 100
6323+
m := MakeMap(mt)
6324+
for i := 0; i < n; i++ {
6325+
kv := KV{int64(i), int64(i+1)}
6326+
m.SetMapIndex(ValueOf(kv), ValueOf(kv))
6327+
}
6328+
6329+
for i := 0; i < n; i++ {
6330+
kv := KV{int64(i), int64(i+1)}
6331+
elem := m.MapIndex(ValueOf(kv)).Interface().(KV)
6332+
if elem != kv {
6333+
t.Errorf("lost m[%v] = %v, want %v", kv, elem, kv)
6334+
}
6335+
}
6336+
}
6337+
63126338
func TestMapOfGCValues(t *testing.T) {
63136339
type T *uintptr
63146340
tt := TypeOf(T(nil))

0 commit comments

Comments
 (0)