Repository navigation
Conversation
Both branches of grow() allocated the new buffer and copied the elements into it, and only the heap branch released the old buffer. grow() now does the allocation and the copy once, then releases the old buffer when it is on the heap. The copy uses current_size, the value that sizes the new buffer and sets the new end. The XTENSOR_ASSERT on the result of allocate(), which came after the buffer had been written to, is removed: allocate() throws on failure. The branch taken when the elements are inline was also where GCC 15 at -O3 replaced m_begin with the inline array and, unable to bound the size, warned that the copy reads past it (-Warray-bounds). The size is at most N there, so the read was never out of bounds; the warning goes away with the duplicated branch. Copying current_size elements, rather than recomputing the count from m_end, also keeps GCC 13 from pairing a one-element buffer with a non-empty copy when grow() is inlined into push_back().
Contributor
Merging this PR will not alter performance1 warning
Comparing |
This branch has not been deployed
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.
Checklist
Description
Both branches of
svector::grow()allocated the new buffer and copied the elements into it; only the heap branch released the old buffer.grow()now allocates and copies once, then releases the old buffer when it is on the heap. The copy usescurrent_size, the value that already sizes the new buffer and sets the new end. TheXTENSOR_ASSERT(new_alloc)that came after the buffer had been written is gone:allocate()throws on failure.The inline branch was also where GCC 15 at
-O3replacedm_beginwith the inline array and, unable to bound the size, warned that the copy reads past it (-Warray-bounds,test_xstorage.cpp). The size is at mostNthere, so the read was never out of bounds; the same pattern in a short standalone program warns with GCC 13 and 15 and runs clean under AddressSanitizer. The warning goes away with the duplicated branch. Copyingcurrent_sizeelements instead of recomputing the count fromm_endalso keeps GCC 13 from pairing a one-element buffer with a non-empty copy whengrow()is inlined intopush_back(), which it did once combined with #2947 and #2951.No behavior change, so no new test;
test_xstoragepasses. This merges cleanly with #2947 and #2949.