Skip to content

Commit e5e6144

Browse files
kabra1110czgdp1807
authored andcommitted
correction in list pop
1 parent 4a43dea commit e5e6144

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/libasr/codegen/llvm_utils.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4432,7 +4432,7 @@ namespace LCompilers {
44324432
std::map<std::string, std::map<std::string, int>>& name2memidx) {
44334433
get_builder0()
44344434
/* Equivalent in C++:
4435-
* while(end_point > pos) {
4435+
* while(end_point > pos + 1) {
44364436
* tmp = pos + 1;
44374437
* list[pos] = list[tmp];
44384438
* pos = tmp;
@@ -4450,8 +4450,6 @@ namespace LCompilers {
44504450
// Get element to return
44514451
llvm::Value* item = read_item(list, LLVM::CreateLoad(*builder, pos_ptr),
44524452
true, *module, LLVM::is_llvm_struct(list_element_type));
4453-
// TODO: Create a macro for the following code to allocate auxiliary variables
4454-
// on stack.
44554453
if( LLVM::is_llvm_struct(list_element_type) ) {
44564454
std::string list_element_type_code = ASRUtils::get_type_code(list_element_type);
44574455
LCOMPILERS_ASSERT(typecode2listtype.find(list_element_type_code) != typecode2listtype.end());
@@ -4469,8 +4467,9 @@ namespace LCompilers {
44694467
// head
44704468
llvm_utils->start_new_block(loophead);
44714469
{
4472-
llvm::Value *cond = builder->CreateICmpSGT(end_point,
4473-
LLVM::CreateLoad(*builder, pos_ptr));
4470+
llvm::Value *cond = builder->CreateICmpSGT(end_point, builder->CreateAdd(
4471+
LLVM::CreateLoad(*builder, pos_ptr),
4472+
llvm::ConstantInt::get(context, llvm::APInt(32, 1))));
44744473
builder->CreateCondBr(cond, loopbody, loopend);
44754474
}
44764475

0 commit comments

Comments
 (0)