mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 11:33:59 +00:00
compiler: Workaround for runtime.boundsCheck in runtime dependencies
This commit is contained in:
@@ -843,11 +843,16 @@ func (c *Compiler) parseExpr(frame *Frame, expr ssa.Value) (llvm.Value, error) {
|
|||||||
|
|
||||||
// Bounds check.
|
// Bounds check.
|
||||||
// LLVM optimizes this away in most cases.
|
// LLVM optimizes this away in most cases.
|
||||||
constZero := llvm.ConstInt(c.intType, 0, false)
|
// TODO: runtime.boundsCheck is undefined in packages imported by
|
||||||
isNegative := c.builder.CreateICmp(llvm.IntSLT, index, constZero, "") // index < 0
|
// package runtime, so we have to remove it. This should be fixed.
|
||||||
isTooBig := c.builder.CreateICmp(llvm.IntSGE, index, buflen, "") // index >= len(value)
|
boundsCheck := c.mod.NamedFunction("runtime.boundsCheck")
|
||||||
isOverflow := c.builder.CreateOr(isNegative, isTooBig, "")
|
if !boundsCheck.IsNil() {
|
||||||
c.builder.CreateCall(c.mod.NamedFunction("runtime.boundsCheck"), []llvm.Value{isOverflow}, "")
|
constZero := llvm.ConstInt(c.intType, 0, false)
|
||||||
|
isNegative := c.builder.CreateICmp(llvm.IntSLT, index, constZero, "") // index < 0
|
||||||
|
isTooBig := c.builder.CreateICmp(llvm.IntSGE, index, buflen, "") // index >= len(value)
|
||||||
|
isOverflow := c.builder.CreateOr(isNegative, isTooBig, "")
|
||||||
|
c.builder.CreateCall(boundsCheck, []llvm.Value{isOverflow}, "")
|
||||||
|
}
|
||||||
|
|
||||||
indices := []llvm.Value{
|
indices := []llvm.Value{
|
||||||
llvm.ConstInt(llvm.Int32Type(), 0, false),
|
llvm.ConstInt(llvm.Int32Type(), 0, false),
|
||||||
|
|||||||
Reference in New Issue
Block a user