MCPcopy
hub / github.com/tinygo-org/tinygo / createDivideByZeroCheck

Method createDivideByZeroCheck

compiler/asserts.go:221–229  ·  view source on GitHub ↗

createDivideByZeroCheck asserts that y is not zero. If it is, a runtime panic will be emitted. This follows the Go specification which says that a divide by zero must cause a run time panic.

(y llvm.Value)

Source from the content-addressed store, hash-verified

219// will be emitted. This follows the Go specification which says that a divide
220// by zero must cause a run time panic.
221func (b *builder) createDivideByZeroCheck(y llvm.Value) {
222 if b.info.nobounds {
223 return
224 }
225
226 // isZero = y == 0
227 isZero := b.CreateICmp(llvm.IntEQ, y, llvm.ConstInt(y.Type(), 0, false), "")
228 b.createRuntimeAssert(isZero, "divbyzero", "divideByZeroPanic")
229}
230
231// createRuntimeAssert is a common function to create a new branch on an assert
232// bool, calling an assert func if the assert value is true (1).

Callers 1

createBinOpMethod · 0.95

Calls 2

createRuntimeAssertMethod · 0.95
TypeMethod · 0.45

Tested by

no test coverage detected