Commit d11f4111 authored by Keith Randall's avatar Keith Randall

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/2055Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent 7a524a10
......@@ -1527,6 +1527,7 @@ func isReflexive(t *rtype) bool {
type gcProg struct {
gc []byte
size uintptr // size of type in bytes
hasPtr bool
}
func (gc *gcProg) append(v byte) {
......@@ -1583,11 +1584,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)
......@@ -1602,7 +1606,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 {
......@@ -1662,7 +1666,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
......@@ -1863,7 +1867,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 + ")"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment