Skip to content

Commit cdfacf7

Browse files
committed
Restore list replace type assumption
1 parent 04c305a commit cdfacf7

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/engine/internal/llvm/instructions/lists.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,17 @@ LLVMInstruction *Lists::buildListReplace(LLVMInstruction *ins)
239239
m_builder.SetInsertPoint(replaceBlock);
240240

241241
llvm::Value *itemPtr = m_utils.getListItem(listPtr, indexInt);
242-
// llvm::Value *typeVar = createListTypeVar(listPtr, itemPtr);
243-
// createListTypeAssumption(listPtr, typeVar, ins->targetType);
244-
245-
/*llvm::Value *typeVar = m_utils.addAlloca(m_builder.getInt32Ty());
246-
llvm::Value *t = m_builder.CreateLoad(m_builder.getInt32Ty(), m_utils.getValueTypePtr(itemPtr));
247-
m_builder.CreateStore(t, typeVar);*/
248-
llvm::Value *typeVar = m_utils.getValueTypePtr(itemPtr);
242+
llvm::Value *typePtr = m_utils.getValueTypePtr(itemPtr);
243+
llvm::Value *loadedType = m_builder.CreateLoad(m_builder.getInt32Ty(), typePtr);
244+
llvm::Value *typeVar = createListTypeVar(listPtr, loadedType);
249245

246+
createListTypeAssumption(listPtr, typeVar, ins->targetType);
250247
m_utils.createValueStore(itemPtr, typeVar, valueArg.second, listType, type);
248+
249+
// Value store may change type, make sure to update it
250+
loadedType = m_builder.CreateLoad(m_builder.getInt32Ty(), typeVar);
251+
m_builder.CreateStore(loadedType, typePtr);
252+
251253
createListTypeUpdate(listPtr, valueArg.second, type);
252254
m_builder.CreateBr(nextBlock);
253255

@@ -470,6 +472,9 @@ void Lists::createListTypeAssumption(const LLVMListPtr &listPtr, llvm::Value *ty
470472

471473
llvm::Value *type = m_builder.CreateLoad(m_builder.getInt32Ty(), typeVar);
472474

475+
if (!inRange)
476+
inRange = m_builder.getInt1(true);
477+
473478
llvm::Value *numberType = m_builder.getInt32(static_cast<uint32_t>(ValueType::Number));
474479
llvm::Value *boolType = m_builder.getInt32(static_cast<uint32_t>(ValueType::Bool));
475480
llvm::Value *stringType = m_builder.getInt32(static_cast<uint32_t>(ValueType::String));

src/engine/internal/llvm/instructions/lists.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Lists : public InstructionGroup
3939

4040
void createListTypeUpdate(const LLVMListPtr &listPtr, const LLVMRegister *newValue, Compiler::StaticType newValueType);
4141
llvm::Value *createListTypeVar(const LLVMListPtr &listPtr, llvm::Value *type);
42-
void createListTypeAssumption(const LLVMListPtr &listPtr, llvm::Value *typeVar, Compiler::StaticType staticType, llvm::Value *inRange);
42+
void createListTypeAssumption(const LLVMListPtr &listPtr, llvm::Value *typeVar, Compiler::StaticType staticType, llvm::Value *inRange = nullptr);
4343
};
4444

4545
} // namespace llvmins

0 commit comments

Comments
 (0)