From: Kyrylo Tkachov <[email protected]>

After commit bf8c0f3aee9 (ipa-inline: credit aggregate copies into the
return slot as eliminated by inlining), constrained.cc fails with excess
errors on 32-bit x86 with -O2 -march=x86-64:

  ranges:582: warning: iteration 9223372036854775791 invokes undefined
  behavior [-Waggressive-loop-optimizations]
  ranges_algo.h:2417: note: within this loop

test03 sorts 10 element views of a long long iota_view.
__final_insertion_sort only calls __unguarded_insertion_sort for ranges
longer than the sort threshold of 16, so that loop is never run.  When it
is inlined, the loop starts at first + 16 and ends at first + 10, so its
iteration count analysis finds the long long iterator overflowing and
warns.  The inlining change only makes the loop visible in this test.  A
reduced test that sorts a take_view of 10 elements gives the same warning
with the compiler before that change.  The test uses an __int128 iota_view
when available, so only targets without __int128 are affected.

Disable the warning for the test on those targets. I think in principle
the warning machinery in GCC could become smarter to not trip up here,
but that is outside the scope of my expertise.

Ok for trunk?
Thanks,
Kyrill

libstdc++-v3/ChangeLog:

        * testsuite/25_algorithms/inplace_merge/constrained.cc: Add
        -Wno-aggressive-loop-optimizations when __int128 is not available.

Signed-off-by: Kyrylo Tkachov <[email protected]>
---
 .../testsuite/25_algorithms/inplace_merge/constrained.cc      | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libstdc++-v3/testsuite/25_algorithms/inplace_merge/constrained.cc 
b/libstdc++-v3/testsuite/25_algorithms/inplace_merge/constrained.cc
index 4c4fdc99637..e06db77fdb2 100644
--- a/libstdc++-v3/testsuite/25_algorithms/inplace_merge/constrained.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/inplace_merge/constrained.cc
@@ -16,6 +16,10 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do run { target c++20 } }
+// Sorting 10 elements never runs __unguarded_insertion_sort, but once it is
+// inlined the loop is analysed and reported as overflowing the iterator of a
+// long long iota_view.
+// { dg-additional-options "-Wno-aggressive-loop-optimizations" { target { ! 
int128 } } }
 
 #include <algorithm>
 #include <ranges>
-- 
2.54.0 (Apple Git-157)

Reply via email to