reflect: fix StructOf GC programs

They are missing a stop byte at the end.

Normally this doesn't matter, but when including a GC program
in another GC program, we strip the last byte. If that last byte
wasn't a stop byte, then we've thrown away part of the program
we actually need.

Fixes #30606

Change-Id: Ie9604beeb84f7f9442e77d31fe64c374ca132cce
Reviewed-on: https://go-review.googlesource.com/c/go/+/165857
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Keith Randall 2019-03-06 10:39:08 -08:00 committed by Keith Randall
parent 1650f1ba0b
commit 05b3db24c1
2 changed files with 21 additions and 0 deletions

View file

@ -2712,6 +2712,7 @@ func StructOf(fields []StructField) Type {
}
}
}
prog = append(prog, 0)
*(*uint32)(unsafe.Pointer(&prog[0])) = uint32(len(prog) - 4)
typ.kind |= kindGCProg
typ.gcdata = &prog[0]

View file

@ -0,0 +1,20 @@
// run
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import "reflect"
func main() {}
func typ(x interface{}) reflect.Type { return reflect.ValueOf(x).Type() }
var x = reflect.New(reflect.StructOf([]reflect.StructField{
{Name: "F5", Type: reflect.StructOf([]reflect.StructField{
{Name: "F4", Type: reflect.ArrayOf(5462,
reflect.SliceOf(typ(uint64(0))))},
})},
}))