From: Ian Lance Taylor Date: Thu, 16 Feb 2017 22:20:24 +0000 (-0800) Subject: reflect: fix bucketOf to only look at ptrdata entries in gcdata X-Git-Tag: go1.9beta1~1473 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b5e51943063a1d78045f0c3ce6c87b424795e643;p=gostls13.git reflect: fix bucketOf to only look at ptrdata entries in gcdata The gcdata field only records ptrdata entries, not size entries. Also fix an obsolete comment: the enforced limit on pointer maps is now 2048 bytes, not 16 bytes. I wasn't able to contruct a test case for this. It would require building a type whose size is greater than 64 bytes but less than 128 bytes, with at least one pointer in first 64 bytes but no pointers after the first 64 bytes, such that the linker arranges for the one byte gcbits value to be immediately followed by a non-zero byte. Change-Id: I9118d3e4ec6f07fd18b72f621c1e5f4fdfe5f80b Reviewed-on: https://go-review.googlesource.com/37142 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements --- diff --git a/src/reflect/type.go b/src/reflect/type.go index 8df9e0ca6b..c182d8c7da 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -2205,9 +2205,6 @@ func bucketOf(ktyp, etyp *rtype) *rtype { // Prepare GC data if any. // A bucket is at most bucketSize*(1+maxKeySize+maxValSize)+2*ptrSize bytes, // or 2072 bytes, or 259 pointer-size words, or 33 bytes of pointer bitmap. - // Normally the enforced limit on pointer maps is 16 bytes, - // but larger ones are acceptable, 33 bytes isn't too too big, - // and it's easier to generate a pointer bitmap than a GC program. // Note that since the key and value are known to be <= 128 bytes, // they're guaranteed to have bitmaps instead of GC programs. var gcdata *byte @@ -2234,7 +2231,7 @@ func bucketOf(ktyp, etyp *rtype) *rtype { panic("reflect: unexpected GC program in MapOf") } kmask := (*[16]byte)(unsafe.Pointer(ktyp.gcdata)) - for i := uintptr(0); i < ktyp.size/ptrSize; i++ { + for i := uintptr(0); i < ktyp.ptrdata/ptrSize; i++ { if (kmask[i/8]>>(i%8))&1 != 0 { for j := uintptr(0); j < bucketSize; j++ { word := base + j*ktyp.size/ptrSize + i @@ -2250,7 +2247,7 @@ func bucketOf(ktyp, etyp *rtype) *rtype { panic("reflect: unexpected GC program in MapOf") } emask := (*[16]byte)(unsafe.Pointer(etyp.gcdata)) - for i := uintptr(0); i < etyp.size/ptrSize; i++ { + for i := uintptr(0); i < etyp.ptrdata/ptrSize; i++ { if (emask[i/8]>>(i%8))&1 != 0 { for j := uintptr(0); j < bucketSize; j++ { word := base + j*etyp.size/ptrSize + i