ssa: add debug info of function return type

This commit is contained in:
Li Jie
2024-09-22 17:43:31 +08:00
parent 70e271959b
commit c6bb4a23ae
3 changed files with 31 additions and 6 deletions

View File

@@ -329,9 +329,12 @@ func (p Function) SetRecover(blk BasicBlock) {
func (p Function) scopeMeta(b diBuilder, pos token.Position) DIScopeMeta {
if p.diFunc == nil {
paramTypes := make([]llvm.Metadata, len(p.params))
sig := p.Type.raw.Type.(*types.Signature)
rt := p.Prog.Type(sig.Results(), InGo)
paramTypes := make([]llvm.Metadata, len(p.params)+1)
paramTypes[0] = b.diType(rt, pos).ll
for i, t := range p.params {
paramTypes[i] = b.diType(t, pos).ll
paramTypes[i+1] = b.diType(t, pos).ll
}
diFuncType := b.di.CreateSubroutineType(llvm.DISubroutineType{
File: b.file(pos.Filename).ll,

View File

@@ -128,7 +128,6 @@ func (b diBuilder) createType(name string, ty Type, pos token.Position) DIType {
Name: name,
SizeInBits: b.prog.SizeOf(b.prog.rawType(t)) * 8,
AlignInBits: uint32(b.prog.sizes.Alignof(t) * 8),
AddressSpace: 0,
})
return &aDIType{typ}
}
@@ -180,6 +179,8 @@ func (b diBuilder) createType(name string, ty Type, pos token.Position) DIType {
case *types.Map:
ty := b.prog.rtType("Map")
return b.createMapType(name, ty, pos)
case *types.Tuple:
return b.createTupleType(name, ty, pos)
default:
panic(fmt.Errorf("can't create debug info of type: %v, %T", ty.RawType(), ty.RawType()))
}
@@ -365,9 +366,8 @@ func (b diBuilder) createPointerType(name string, ty Type, pos token.Position) D
return &aDIType{ll: b.di.CreatePointerType(llvm.DIPointerType{
Name: name,
Pointee: b.diType(ty, pos).ll,
SizeInBits: b.prog.SizeOf(ty) * 8,
AlignInBits: uint32(b.prog.sizes.Alignof(ty.RawType())) * 8,
AddressSpace: 0,
SizeInBits: b.prog.SizeOf(b.prog.VoidPtr()) * 8,
AlignInBits: uint32(b.prog.sizes.Alignof(b.prog.VoidPtr().RawType())) * 8,
})}
}
@@ -421,6 +421,26 @@ func (b diBuilder) createStructType(name string, ty Type, pos token.Position) (r
})
}
func (b diBuilder) createTupleType(name string, ty Type, pos token.Position) DIType {
tupleType := ty.RawType().(*types.Tuple)
if tupleType.Len() == 0 {
return &aDIType{}
}
if tupleType.Len() == 1 {
t := b.prog.rawType(tupleType.At(0).Type())
return b.diType(t, pos)
}
return b.doCreateStructType(name, ty, pos, func(ditStruct DIType) []llvm.Metadata {
fields := make([]llvm.Metadata, ty.RawType().(*types.Tuple).Len())
for i := 0; i < ty.RawType().(*types.Tuple).Len(); i++ {
field := ty.RawType().(*types.Tuple).At(i)
tyField := b.prog.rawType(field.Type())
fields[i] = b.createMemberTypeEx(field.Name(), ty, tyField, i, pos, 0)
}
return fields
})
}
func (b diBuilder) createFuncPtrType(name string, ty Type, pos token.Position) DIType {
ptr := b.prog.VoidPtr()
return &aDIType{ll: b.di.CreatePointerType(llvm.DIPointerType{

View File

@@ -109,6 +109,8 @@ func (p goTypes) cvtType(typ types.Type) (raw types.Type, cvt bool) {
if elem, cvt := p.cvtType(t.Elem()); cvt {
return types.NewChan(t.Dir(), elem), true
}
case *types.Tuple:
return p.cvtTuple(t)
default:
panic(fmt.Sprintf("cvtType: unexpected type - %T", typ))
}