From e5e6144f1a19e204c0c8ce6a9cc91d7574333f29 Mon Sep 17 00:00:00 2001 From: kabra1110 Date: Mon, 31 Jul 2023 07:17:58 +0530 Subject: [PATCH] correction in list pop --- src/libasr/codegen/llvm_utils.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libasr/codegen/llvm_utils.cpp b/src/libasr/codegen/llvm_utils.cpp index 076f9594c7..07c4649b83 100644 --- a/src/libasr/codegen/llvm_utils.cpp +++ b/src/libasr/codegen/llvm_utils.cpp @@ -4432,7 +4432,7 @@ namespace LCompilers { std::map>& name2memidx) { get_builder0() /* Equivalent in C++: - * while(end_point > pos) { + * while(end_point > pos + 1) { * tmp = pos + 1; * list[pos] = list[tmp]; * pos = tmp; @@ -4450,8 +4450,6 @@ namespace LCompilers { // Get element to return llvm::Value* item = read_item(list, LLVM::CreateLoad(*builder, pos_ptr), true, *module, LLVM::is_llvm_struct(list_element_type)); - // TODO: Create a macro for the following code to allocate auxiliary variables - // on stack. if( LLVM::is_llvm_struct(list_element_type) ) { std::string list_element_type_code = ASRUtils::get_type_code(list_element_type); LCOMPILERS_ASSERT(typecode2listtype.find(list_element_type_code) != typecode2listtype.end()); @@ -4469,8 +4467,9 @@ namespace LCompilers { // head llvm_utils->start_new_block(loophead); { - llvm::Value *cond = builder->CreateICmpSGT(end_point, - LLVM::CreateLoad(*builder, pos_ptr)); + llvm::Value *cond = builder->CreateICmpSGT(end_point, builder->CreateAdd( + LLVM::CreateLoad(*builder, pos_ptr), + llvm::ConstantInt::get(context, llvm::APInt(32, 1)))); builder->CreateCondBr(cond, loopbody, loopend); }