@@ -63,20 +63,27 @@ ProcessResult Lists::process(LLVMInstruction *ins)
63
63
64
64
LLVMInstruction *Lists::buildClearList (LLVMInstruction *ins)
65
65
{
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
+ }
69
71
70
72
return ins->next ;
71
73
}
72
74
73
75
LLVMInstruction *Lists::buildRemoveListItem (LLVMInstruction *ins)
74
76
{
77
+ // No-op in empty lists
78
+ if (ins->targetType == Compiler::StaticType::Void)
79
+ return ins->next ;
80
+
75
81
llvm::LLVMContext &llvmCtx = m_utils.llvmCtx ();
76
82
llvm::Function *function = m_utils.function ();
77
83
78
84
assert (ins->args .size () == 1 );
79
85
const auto &arg = ins->args [0 ];
86
+
80
87
LLVMListPtr &listPtr = m_utils.listPtr (ins->targetList );
81
88
82
89
// Range check
@@ -171,6 +178,10 @@ LLVMInstruction *Lists::buildInsertToList(LLVMInstruction *ins)
171
178
172
179
LLVMInstruction *Lists::buildListReplace (LLVMInstruction *ins)
173
180
{
181
+ // No-op in empty lists
182
+ if (ins->targetType == Compiler::StaticType::Void)
183
+ return ins->next ;
184
+
174
185
llvm::LLVMContext &llvmCtx = m_utils.llvmCtx ();
175
186
llvm::Function *function = m_utils.function ();
176
187
@@ -216,6 +227,13 @@ LLVMInstruction *Lists::buildGetListContents(LLVMInstruction *ins)
216
227
217
228
LLVMInstruction *Lists::buildGetListItem (LLVMInstruction *ins)
218
229
{
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
+
219
237
assert (ins->args .size () == 1 );
220
238
const auto &arg = ins->args [0 ];
221
239
LLVMListPtr &listPtr = m_utils.listPtr (ins->targetList );
0 commit comments