From bf73516259b3028ade4b9e48499e988523f52542 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 28 Aug 2023 04:19:19 -0400 Subject: [PATCH] compiler: Handle nil array and struct constants This is necessary for tools 0.9.0, which started lifting those since https://github.com/golang/tools/commit/71ea8f168c160da91116b4ddbd577a8fc95aa334 --- compiler/compiler.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/compiler.go b/compiler/compiler.go index 6dd43935..cb3a892a 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -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.