@@ -184,7 +184,7 @@ LLVMInstruction *Lists::buildInsertToList(LLVMInstruction *ins)
184184 // Range check
185185 llvm::Value *indexDouble = m_utils.castValue (indexArg.second , indexArg.first );
186186 llvm::Value *indexInt = getIndex (listPtr, indexDouble);
187- llvm::Value *inRange = createSizeRangeCheck (listPtr, indexInt, " insertToList.indexInRange" );
187+ llvm::Value *inRange = createSizeRangeCheck (listPtr, indexInt, " insertToList.indexInRange" , true );
188188
189189 llvm::BasicBlock *insertBlock = llvm::BasicBlock::Create (llvmCtx, " " , function);
190190 llvm::BasicBlock *nextBlock = llvm::BasicBlock::Create (llvmCtx, " " , function);
@@ -367,10 +367,14 @@ llvm::Value *Lists::getIndex(const LLVMListPtr &listPtr, llvm::Value *indexDoubl
367367 return m_builder.CreateSelect (isNegative, llvm::ConstantInt::get (m_builder.getInt64Ty (), INT64_MAX), m_builder.CreateFPToUI (indexDouble, m_builder.getInt64Ty (), " listIndex.int" ));
368368}
369369
370- llvm::Value *Lists::createSizeRangeCheck (const LLVMListPtr &listPtr, llvm::Value *indexInt, const std::string &name)
370+ llvm::Value *Lists::createSizeRangeCheck (const LLVMListPtr &listPtr, llvm::Value *indexInt, const std::string &name, bool includeSize )
371371{
372372 llvm::Value *size = m_utils.getListSize (listPtr);
373- return m_builder.CreateICmpULT (indexInt, size, name);
373+
374+ if (includeSize)
375+ return m_builder.CreateICmpULE (indexInt, size, name);
376+ else
377+ return m_builder.CreateICmpULT (indexInt, size, name);
374378}
375379
376380void Lists::createListTypeUpdate (const LLVMListPtr &listPtr, const LLVMRegister *newValue, Compiler::StaticType newValueType)
0 commit comments