Commit 17f888c5 authored by Keith Randall's avatar Keith Randall Committed by Keith Randall

reflect: fix typeptrdata

We can't use ptrdata inside of typeptrdata, because it won't be
properly initialized until typeptrdata returns.

Fixes #31039

Change-Id: Ib8c89191a7e4cce678a05d351bb6ded81ba23aae
Reviewed-on: https://go-review.googlesource.com/c/go/+/169317
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent c4f87ed2
......@@ -2775,20 +2775,20 @@ func runtimeStructField(field StructField) structField {
// containing pointer data. Anything after this offset is scalar data.
// keep in sync with ../cmd/compile/internal/gc/reflect.go
func typeptrdata(t *rtype) uintptr {
if !t.pointers() {
return 0
}
switch t.Kind() {
case Struct:
st := (*structType)(unsafe.Pointer(t))
// find the last field that has pointers.
field := 0
field := -1
for i := range st.fields {
ft := st.fields[i].typ
if ft.pointers() {
field = i
}
}
if field == -1 {
return 0
}
f := st.fields[field]
return f.offset() + f.typ.ptrdata
......
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