Compiling LLVM with assertions enabled revealed some bugs in TinyGo that
weren't caught by normal verifying of the LLVM module.
Этот коммит содержится в:
Ayke van Laethem 2019-08-09 20:07:52 +02:00 коммит произвёл Ron Evans
родитель 562ad740da
коммит b7cb10519c

Просмотреть файл

@ -66,10 +66,7 @@ func (c *Compiler) getTypeCode(typ types.Type) llvm.Value {
case *types.Struct: case *types.Struct:
// Take a pointer to the typecodeID of the first field (if it exists). // Take a pointer to the typecodeID of the first field (if it exists).
structGlobal := c.makeStructTypeFields(typ) structGlobal := c.makeStructTypeFields(typ)
references = llvm.ConstGEP(structGlobal, []llvm.Value{ references = llvm.ConstBitCast(structGlobal, global.Type())
llvm.ConstInt(llvm.Int32Type(), 0, false),
llvm.ConstInt(llvm.Int32Type(), 0, false),
})
} }
if !references.IsNil() { if !references.IsNil() {
// Set the 'references' field of the runtime.typecodeID struct. // Set the 'references' field of the runtime.typecodeID struct.
@ -96,12 +93,12 @@ func (c *Compiler) makeStructTypeFields(typ *types.Struct) llvm.Value {
fieldGlobalValue := c.getZeroValue(runtimeStructField) fieldGlobalValue := c.getZeroValue(runtimeStructField)
fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, c.getTypeCode(typ.Field(i).Type()), []uint32{0}) fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, c.getTypeCode(typ.Field(i).Type()), []uint32{0})
fieldName := c.makeGlobalBytes([]byte(typ.Field(i).Name()), "reflect/types.structFieldName") fieldName := c.makeGlobalBytes([]byte(typ.Field(i).Name()), "reflect/types.structFieldName")
fieldName.SetLinkage(llvm.PrivateLinkage)
fieldName.SetUnnamedAddr(true)
fieldName = llvm.ConstGEP(fieldName, []llvm.Value{ fieldName = llvm.ConstGEP(fieldName, []llvm.Value{
llvm.ConstInt(llvm.Int32Type(), 0, false), llvm.ConstInt(llvm.Int32Type(), 0, false),
llvm.ConstInt(llvm.Int32Type(), 0, false), llvm.ConstInt(llvm.Int32Type(), 0, false),
}) })
fieldName.SetLinkage(llvm.PrivateLinkage)
fieldName.SetUnnamedAddr(true)
fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldName, []uint32{1}) fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldName, []uint32{1})
if typ.Tag(i) != "" { if typ.Tag(i) != "" {
fieldTag := c.makeGlobalBytes([]byte(typ.Tag(i)), "reflect/types.structFieldTag") fieldTag := c.makeGlobalBytes([]byte(typ.Tag(i)), "reflect/types.structFieldTag")