-
Notifications
You must be signed in to change notification settings - Fork 170
LLVM: Fix list.insert()
when given index is greater than length of the list
#1565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test for it or point me to any existing tests which verify that your change works correctly.
I have added a test case now. Basically, it handles cases when first argument is greater than list length. |
@czgdp1807
|
adjusted_pos, | ||
llvm::ConstantInt::get(context, llvm::APInt(32, 0)) | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like an issue with edge case. Note that current_end_point
equals len(list)
all the times.
lpython/src/libasr/codegen/llvm_utils.cpp
Lines 2252 to 2254 in 57ebbc8
llvm::Value* LLVMList::len(llvm::Value* list) { | |
return LLVM::CreateLoad(*builder, get_pointer_to_current_end_point(list)); | |
} |
Consider
list.insert(position,element)
, In python ifposition
is greater than the length of list then by default theelement
is inserted atposition = len(list)
.On master -
On branch -