@@ -63,20 +63,27 @@ ProcessResult Lists::process(LLVMInstruction *ins)
6363
6464LLVMInstruction *Lists::buildClearList (LLVMInstruction *ins)
6565{
66- assert (ins->args .size () == 0 );
67- LLVMListPtr &listPtr = m_utils.listPtr (ins->targetList );
68- m_builder.CreateCall (m_utils.functions ().resolve_list_clear (), listPtr.ptr );
66+ if (ins->targetType != Compiler::StaticType::Void) { // do not clear a list that is already empty
67+ assert (ins->args .size () == 0 );
68+ LLVMListPtr &listPtr = m_utils.listPtr (ins->targetList );
69+ m_builder.CreateCall (m_utils.functions ().resolve_list_clear (), listPtr.ptr );
70+ }
6971
7072 return ins->next ;
7173}
7274
7375LLVMInstruction *Lists::buildRemoveListItem (LLVMInstruction *ins)
7476{
77+ // No-op in empty lists
78+ if (ins->targetType == Compiler::StaticType::Void)
79+ return ins->next ;
80+
7581 llvm::LLVMContext &llvmCtx = m_utils.llvmCtx ();
7682 llvm::Function *function = m_utils.function ();
7783
7884 assert (ins->args .size () == 1 );
7985 const auto &arg = ins->args [0 ];
86+
8087 LLVMListPtr &listPtr = m_utils.listPtr (ins->targetList );
8188
8289 // Range check
@@ -171,6 +178,10 @@ LLVMInstruction *Lists::buildInsertToList(LLVMInstruction *ins)
171178
172179LLVMInstruction *Lists::buildListReplace (LLVMInstruction *ins)
173180{
181+ // No-op in empty lists
182+ if (ins->targetType == Compiler::StaticType::Void)
183+ return ins->next ;
184+
174185 llvm::LLVMContext &llvmCtx = m_utils.llvmCtx ();
175186 llvm::Function *function = m_utils.function ();
176187
@@ -216,6 +227,13 @@ LLVMInstruction *Lists::buildGetListContents(LLVMInstruction *ins)
216227
217228LLVMInstruction *Lists::buildGetListItem (LLVMInstruction *ins)
218229{
230+ // Return empty string for empty lists
231+ if (ins->targetType == Compiler::StaticType::Void) {
232+ LLVMConstantRegister nullReg (Compiler::StaticType::String, " " );
233+ ins->functionReturnReg ->value = m_utils.createValue (static_cast <LLVMRegister *>(&nullReg));
234+ return ins->next ;
235+ }
236+
219237 assert (ins->args .size () == 1 );
220238 const auto &arg = ins->args [0 ];
221239 LLVMListPtr &listPtr = m_utils.listPtr (ins->targetList );
0 commit comments