mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-20 04:19:04 +00:00
compiler: avoid some obviously false nil checks
Pointers to globals are never nil.
This commit is contained in:
committed by
Ron Evans
parent
7ada00790c
commit
f94af9f61e
@@ -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
|
// has no effect in well-behaved programs, but makes sure no uncaught nil
|
||||||
// pointer dereferences exist in valid Go code.
|
// pointer dereferences exist in valid Go code.
|
||||||
func (c *Compiler) emitNilCheck(frame *Frame, ptr llvm.Value, blockPrefix string) {
|
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.
|
// Check whether this is a nil pointer.
|
||||||
faultBlock := c.ctx.AddBasicBlock(frame.fn.LLVMFn, blockPrefix+".nil")
|
faultBlock := c.ctx.AddBasicBlock(frame.fn.LLVMFn, blockPrefix+".nil")
|
||||||
nextBlock := c.ctx.AddBasicBlock(frame.fn.LLVMFn, blockPrefix+".next")
|
nextBlock := c.ctx.AddBasicBlock(frame.fn.LLVMFn, blockPrefix+".next")
|
||||||
|
|||||||
Reference in New Issue
Block a user