compiler: fix nil constant interface

A nil interface has no dynamic type (or: nil dynamic type). Don't try to
use the static type as the dynamic type, because these are different.
Этот коммит содержится в:
Ayke van Laethem 2018-09-03 01:01:24 +02:00
родитель 4ed04309a3
коммит c100e4d67f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E97FF5335DFDFDED
2 изменённых файлов: 4 добавлений и 10 удалений

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

@ -2279,16 +2279,10 @@ func (c *Compiler) parseConst(expr *ssa.Const) (llvm.Value, error) {
if expr.Value != nil { if expr.Value != nil {
return llvm.Value{}, errors.New("non-nil interface constant") return llvm.Value{}, errors.New("non-nil interface constant")
} }
itfTypeNum, ok := c.ir.TypeNum(expr.Type()) // Create a generic nil interface with no dynamic type (typecode=0).
if itfTypeNum >= 1<<16 {
return llvm.Value{}, errors.New("interface typecodes do not fit in a 16-bit integer")
}
if !ok {
panic("interface number is unknown")
}
fields := []llvm.Value{ fields := []llvm.Value{
llvm.ConstInt(llvm.Int16Type(), uint64(itfTypeNum), false), llvm.ConstInt(llvm.Int16Type(), 0, false),
llvm.Undef(c.i8ptrType), llvm.ConstPointerNull(c.i8ptrType),
} }
itf := llvm.ConstNamedStruct(c.mod.GetTypeByName("runtime._interface"), fields) itf := llvm.ConstNamedStruct(c.mod.GetTypeByName("runtime._interface"), fields)
return itf, nil return itf, nil

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

@ -103,7 +103,7 @@ func (p *Program) AnalyseCallgraph() {
// Find all types that are put in an interface. // Find all types that are put in an interface.
func (p *Program) AnalyseInterfaceConversions() { func (p *Program) AnalyseInterfaceConversions() {
// Clear, if AnalyseTypes has been called before. // Clear, if AnalyseTypes has been called before.
p.typesWithoutMethods = map[string]int{"interface{}": 0, "error": 1} p.typesWithoutMethods = map[string]int{"nil": 0}
p.typesWithMethods = map[string]*InterfaceType{} p.typesWithMethods = map[string]*InterfaceType{}
for _, f := range p.Functions { for _, f := range p.Functions {