@@ -18,6 +18,12 @@ import (
1818 "tinygo.org/x/go-llvm"
1919)
2020
21+ // numMethodHasMethodSet is a flag in bit 15 of the numMethod field (uint16) in
22+ // Named, Pointer, and Struct type descriptors. When set, an inline method set
23+ // is present in the type descriptor. Must match the constant in
24+ // src/internal/reflectlite/type.go.
25+ const numMethodHasMethodSet = 0x8000
26+
2127// Type kinds for basic types.
2228// They must match the constants for the Kind type in src/reflect/type.go.
2329var basicTypes = [... ]uint8 {
@@ -321,8 +327,11 @@ func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value {
321327 }
322328 pkgPathPtr := c .pkgPathPtr (pkgpath )
323329 namedNumMethods := uint64 (numMethods )
330+ if namedNumMethods & numMethodHasMethodSet != 0 {
331+ panic ("numMethods overflow: too many exported methods on named type " + name )
332+ }
324333 if len (methods ) > 0 {
325- namedNumMethods |= 0x8000 // numMethodHasMethodSet flag
334+ namedNumMethods |= numMethodHasMethodSet
326335 }
327336 typeFields = []llvm.Value {
328337 llvm .ConstInt (c .ctx .Int16Type (), namedNumMethods , false ), // numMethods
@@ -359,8 +368,11 @@ func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value {
359368 }
360369 case * types.Pointer :
361370 ptrNumMethods := uint64 (numMethods )
371+ if ptrNumMethods & numMethodHasMethodSet != 0 {
372+ panic ("numMethods overflow: too many exported methods on pointer type" )
373+ }
362374 if len (methods ) > 0 {
363- ptrNumMethods |= 0x8000 // numMethodHasMethodSet flag
375+ ptrNumMethods |= numMethodHasMethodSet
364376 }
365377 typeFields = []llvm.Value {
366378 llvm .ConstInt (c .ctx .Int16Type (), ptrNumMethods , false ), // numMethods
@@ -396,8 +408,11 @@ func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value {
396408 llvmStructType := c .getLLVMType (typ )
397409 size := c .targetData .TypeStoreSize (llvmStructType )
398410 structNumMethods := uint64 (numMethods )
411+ if structNumMethods & numMethodHasMethodSet != 0 {
412+ panic ("numMethods overflow: too many exported methods on struct type" )
413+ }
399414 if len (methods ) > 0 {
400- structNumMethods |= 0x8000 // numMethodHasMethodSet flag
415+ structNumMethods |= numMethodHasMethodSet
401416 }
402417 typeFields = []llvm.Value {
403418 llvm .ConstInt (c .ctx .Int16Type (), structNumMethods , false ), // numMethods
0 commit comments