From f94af9f61e048a5346715b6e662f7165540024ba Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 18 May 2019 14:36:18 +0200 Subject: [PATCH] compiler: avoid some obviously false nil checks Pointers to globals are never nil. --- compiler/asserts.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/asserts.go b/compiler/asserts.go index 0affd81e..743ac46a 100644 --- a/compiler/asserts.go +++ b/compiler/asserts.go @@ -114,6 +114,11 @@ func (c *Compiler) emitSliceBoundsCheck(frame *Frame, capacity, low, high llvm.V // has no effect in well-behaved programs, but makes sure no uncaught nil // pointer dereferences exist in valid Go code. func (c *Compiler) emitNilCheck(frame *Frame, ptr llvm.Value, blockPrefix string) { + // Check whether we need to emit this check at all. + if !ptr.IsAGlobalValue().IsNil() { + return + } + // Check whether this is a nil pointer. faultBlock := c.ctx.AddBasicBlock(frame.fn.LLVMFn, blockPrefix+".nil") nextBlock := c.ctx.AddBasicBlock(frame.fn.LLVMFn, blockPrefix+".next")