Repository navigation
Conversation
GCC 13 and 15 emit -Warray-bounds at -O2/-O3 on a std::copy from a
std::array<std::size_t, 1> member into another std::array<std::size_t, 1>.
When the array is a member at a non-zero offset, GCC does not fold the
length of the source range and warns on the memmove branch that libstdc++
keeps for ranges of more than one element. That branch never runs. User
code as simple as assigning 0.5 * (even + odd) to a 1-D view gets the
warning.
Minimal reproducer without xtensor:
struct holder { std::size_t m_size; std::array<std::size_t, 1> m_shape; };
std::array<std::size_t, 1> f(const holder& h)
{
std::array<std::size_t, 1> s;
std::copy(h.m_shape.cbegin(), h.m_shape.cend(), s.begin());
return s;
}
std::copy_n takes the count directly, and size() is a constant for
std::array, so GCC drops the branch. In each changed site the destination
is sized from the same source, so the number of copied elements does not
change. Changed sites: xfunction::broadcast_shape, the xbroadcast
constructor, flip (shape and strides) and average with multi-dimensional
weights.
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.
Description
GCC 13 and 15 emit
-Warray-boundsat-O2/-O3on ordinary code using fixed-rank containers, for example assigning0.5 * (even + odd)to a 1-Dxtensorview. The warning comes from astd::copybetween twostd::array<std::size_t, 1>when the source is a member at a non-zero offset. GCC does not fold the length of the range and warns on thememmovebranch that libstdc++ keeps for ranges of more than one element. That branch never runs. Reproducer without xtensor:These copies now use
std::copy_n(src.begin(), src.size(), dst.begin()).size()is a constant forstd::array, so GCC drops the branch. At each site the destination is sized from the same source, so the copied elements do not change. Changed sites:xfunction::broadcast_shape, thexbroadcastconstructor,flip(shape and strides), andaveragewith multi-dimensional weights.std::copy(data(), data() + size())andstd::ranges::copystill warn.No unit test, since this is a compile-time warning and CI does not build with
-Wallon GCC. A file using 1-D, 2-D and 3-D views, reductions, broadcasting,flipandxtensor_fixednow compiles without warnings with GCC 13.4 and 15.3 at-O2and-O3with-Wall -Wextra, with and without xsimd.