https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109442
--- Comment #26 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
After some more checking we need help from libstdc++ here. Problem is that size
does the pointer subtraction which is always positive, but we do not know it,
and then converts it to size_type.
The following makes us to optimize the size check out.
libstdc++-v3/ChangeLog:
* include/bits/stl_vector.h: Vector size is never negative.
diff --git a/libstdc++-v3/include/bits/stl_vector.h
b/libstdc++-v3/include/bits/stl_vector.h
index df48ba3377f..59c9348724a 100644
--- a/libstdc++-v3/include/bits/stl_vector.h
+++ b/libstdc++-v3/include/bits/stl_vector.h
@@ -1114,7 +1114,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
size_type
size() const _GLIBCXX_NOEXCEPT
- { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
+ {
+ ptrdiff_t __dif = this->_M_impl._M_finish - this->_M_impl._M_start;
+ if (__dif < 0)
+ __builtin_unreachable ();
+ return size_type(__dif);
+ }
/** Returns the size() of the largest possible %vector. */
_GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR