compiler: Handle nil array and struct constants

This is necessary for tools 0.9.0, which started lifting those since
71ea8f168c
Этот коммит содержится в:
Elliott Sales de Andrade 2023-08-28 04:19:19 -04:00 коммит произвёл Ron Evans
родитель 43d282174f
коммит bf73516259

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

@ -3005,6 +3005,11 @@ func (c *compilerContext) createConst(expr *ssa.Const, pos token.Pos) llvm.Value
panic("expected nil pointer constant")
}
return llvm.ConstPointerNull(c.getLLVMType(typ))
case *types.Array:
if expr.Value != nil {
panic("expected nil array constant")
}
return llvm.ConstNull(c.getLLVMType(expr.Type()))
case *types.Slice:
if expr.Value != nil {
panic("expected nil slice constant")
@ -3018,6 +3023,11 @@ func (c *compilerContext) createConst(expr *ssa.Const, pos token.Pos) llvm.Value
llvmLen, // cap
}, false)
return slice
case *types.Struct:
if expr.Value != nil {
panic("expected nil struct constant")
}
return llvm.ConstNull(c.getLLVMType(expr.Type()))
case *types.Map:
if !expr.IsNil() {
// I believe this is not allowed by the Go spec.