From 3c2639ad5520434a37488cedf3917630e7266964 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 3 May 2019 22:09:22 +0200 Subject: [PATCH] compiler: insert nil checks when storing to a pointer This does increase code size, but it is necessary to avoid undefined behavior. --- compiler/compiler.go | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/compiler.go b/compiler/compiler.go index 48a03550..db5d442c 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -1054,6 +1054,7 @@ func (c *Compiler) parseInstr(frame *Frame, instr ssa.Instruction) { case *ssa.Store: llvmAddr := c.getValue(frame, instr.Addr) llvmVal := c.getValue(frame, instr.Val) + c.emitNilCheck(frame, llvmAddr, "store") if c.targetData.TypeAllocSize(llvmVal.Type()) == 0 { // nothing to store return