Don't create copy of variable when reverse indexing with indexing overloaded#3259
Closed
Book-reader wants to merge 1 commit into
Closed
Don't create copy of variable when reverse indexing with indexing overloaded#3259Book-reader wants to merge 1 commit into
Book-reader wants to merge 1 commit into
Conversation
[] or &[] overloaded
Collaborator
|
This does not quite solve toe problem. What you need to do is get a reference (if possible) to it and then use that instead. I've pushed another fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #3258.
Please let me know if there is a better way to do this.
This is what the LLVM IR generated from https://github.com/Book-reader/c3c/blob/aeeb35c46702c79768cc4e8f6332769949a1874f/test/test_suite/overloading/reverse_index.c3t looked like before these changes:
It would allocate a new copy of the original value named
%.anon*for each reverse-indexing, making&t[^1]return a pointer to a different value each time it was used.This doesn't affect
Lists in most cases because they store their contents on the heap and the pointer to it would be shared between the copies, but appending to aListusingarr[^0] = xwould not update the length of the original list and could reallocate the array and cause the original List to point to freed memory.