mirror of https://github.com/golang/go.git
[release-branch.go1.4] reflect: add kindNoPointers if a function layout has no pointers.
malloc checks kindNoPointers and if it is not set and the object
is one pointer in size, it assumes it contains a pointer. So we
must set kindNoPointers correctly; it isn't just a hint.
Fixes #9425
Change-Id: Ia43da23cc3298d6e3d6dbdf66d32e9678f0aedcf
Reviewed-on: https://go-review.googlesource.com/2055
Reviewed-by: Russ Cox <rsc@golang.org>
(cherry picked from commit d11f411181)
Reviewed-on: https://go-review.googlesource.com/2800
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
parent
cc7bbb0ae9
commit
957ed90d0e
|
|
@ -1498,8 +1498,9 @@ func MapOf(key, elem Type) Type {
|
|||
|
||||
// gcProg is a helper type for generatation of GC pointer info.
|
||||
type gcProg struct {
|
||||
gc []byte
|
||||
size uintptr // size of type in bytes
|
||||
gc []byte
|
||||
size uintptr // size of type in bytes
|
||||
hasPtr bool
|
||||
}
|
||||
|
||||
func (gc *gcProg) append(v byte) {
|
||||
|
|
@ -1560,11 +1561,14 @@ func (gc *gcProg) appendWord(v byte) {
|
|||
gc.gc[nptr/2] &= ^(3 << ((nptr%2)*4 + 2))
|
||||
gc.gc[nptr/2] |= v << ((nptr%2)*4 + 2)
|
||||
gc.size += ptrsize
|
||||
if v == bitsPointer {
|
||||
gc.hasPtr = true
|
||||
}
|
||||
}
|
||||
|
||||
func (gc *gcProg) finalize() unsafe.Pointer {
|
||||
func (gc *gcProg) finalize() (unsafe.Pointer, bool) {
|
||||
if gc.size == 0 {
|
||||
return nil
|
||||
return nil, false
|
||||
}
|
||||
ptrsize := unsafe.Sizeof(uintptr(0))
|
||||
gc.align(ptrsize)
|
||||
|
|
@ -1579,7 +1583,7 @@ func (gc *gcProg) finalize() unsafe.Pointer {
|
|||
gc.appendWord(extractGCWord(gc.gc, i))
|
||||
}
|
||||
}
|
||||
return unsafe.Pointer(&gc.gc[0])
|
||||
return unsafe.Pointer(&gc.gc[0]), gc.hasPtr
|
||||
}
|
||||
|
||||
func extractGCWord(gc []byte, i uintptr) byte {
|
||||
|
|
@ -1639,7 +1643,7 @@ func bucketOf(ktyp, etyp *rtype) *rtype {
|
|||
|
||||
b := new(rtype)
|
||||
b.size = gc.size
|
||||
b.gc[0] = gc.finalize()
|
||||
b.gc[0], _ = gc.finalize()
|
||||
s := "bucket(" + *ktyp.string + "," + *etyp.string + ")"
|
||||
b.string = &s
|
||||
return b
|
||||
|
|
@ -1840,7 +1844,11 @@ func funcLayout(t *rtype, rcvr *rtype) (frametype *rtype, argSize, retOffset uin
|
|||
// build dummy rtype holding gc program
|
||||
x := new(rtype)
|
||||
x.size = gc.size
|
||||
x.gc[0] = gc.finalize()
|
||||
var hasPtr bool
|
||||
x.gc[0], hasPtr = gc.finalize()
|
||||
if !hasPtr {
|
||||
x.kind |= kindNoPointers
|
||||
}
|
||||
var s string
|
||||
if rcvr != nil {
|
||||
s = "methodargs(" + *rcvr.string + ")(" + *t.string + ")"
|
||||
|
|
|
|||
Loading…
Reference in New Issue