From ed76775e18404f3fccacd3c2326c05a2d3332821 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Wed, 21 May 2025 17:03:37 -0400 Subject: [PATCH] libstdc++: Fix -Warray-bounds warning in std::vector Resolves: RHEL-90244 --- gcc.spec | 12 +++++-- gcc14-RHEL-90244.patch | 81 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 gcc14-RHEL-90244.patch diff --git a/gcc.spec b/gcc.spec index f77c812..c5008f3 100644 --- a/gcc.spec +++ b/gcc.spec @@ -11,7 +11,7 @@ BuildRequires: scl-utils-build %global gcc_major 14 # Note, gcc_release must be integer, if you want to add suffixes to # %%{release}, append them after %%{gcc_release} on Release: line. -%global gcc_release 7 +%global gcc_release 8 %global nvptx_tools_gitrev 87ce9dc5999e5fca2e1d3478a30888d9864c9804 %global newlib_cygwin_gitrev d45261f62a15f8abd94a1031020b9a9f455e4eed %global isl_version 0.24 @@ -152,7 +152,7 @@ BuildRequires: scl-utils-build Summary: GCC version %{gcc_major} Name: %{?scl_prefix}gcc Version: %{gcc_version} -Release: %{gcc_release}.1%{?dist} +Release: %{gcc_release}%{?dist} # License notes for some of the less obvious ones: # gcc/doc/cppinternals.texi: Linux-man-pages-copyleft-2-para # isl: MIT, BSD-2-Clause @@ -361,6 +361,8 @@ Patch3015: 0018-Use-CXX11-ABI.patch Patch3017: 0020-more-fixes.patch Patch3018: 0021-libstdc++-disable-tests.patch +Patch4000: gcc14-RHEL-90244.patch + %if 0%{?rhel} == 9 %global nonsharedver 110 %endif @@ -724,6 +726,9 @@ touch -r isl-0.24/m4/ax_prog_cxx_for_build.m4 isl-0.24/m4/ax_prog_cc_for_build.m %patch -P3017 -p1 -b .dts-test-17~ %patch -P3018 -p1 -b .dts-test-18~ +# Bugfix backports. +%patch -P4000 -p1 -b .RHEL-90244~ + find gcc/testsuite -name \*.pr96939~ | xargs rm -f echo 'Red Hat %{version}-%{gcc_release}' > gcc/DEV-PHASE @@ -2796,6 +2801,9 @@ fi %endif %changelog +* Thu May 22 2025 Siddhesh Poyarekar 14.2.1-8 +- libstdc++: Fix -Warray-bounds warning in std::vector (RHEL-90244) + * Fri Feb 7 2025 Marek Polacek 14.2.1-7.1 - disable jQuery use, don't ship jquery.js (CVE-2020-11023, RHEL-78387) diff --git a/gcc14-RHEL-90244.patch b/gcc14-RHEL-90244.patch new file mode 100644 index 0000000..4f0a031 --- /dev/null +++ b/gcc14-RHEL-90244.patch @@ -0,0 +1,81 @@ +From 9d5baaa92c6609191fd2488389562ac1ad1f0fb2 Mon Sep 17 00:00:00 2001 +From: Jonathan Wakely +Date: Fri, 28 Mar 2025 15:41:41 +0000 +Subject: [PATCH] libstdc++: Fix -Warray-bounds warning in std::vector + [PR110498] +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +In this case, we need to tell the compiler that the current size is not +larger than the new size so that all the existing elements can be copied +to the new storage. This avoids bogus warnings about overflowing the new +storage when the compiler can't tell that that cannot happen. + +We might as well also hoist the loads of begin() and end() before the +allocation too. All callers will have loaded at least begin() before +calling _M_reallocate. + +libstdc++-v3/ChangeLog: + + PR libstdc++/110498 + * include/bits/vector.tcc (vector::_M_reallocate): + Hoist loads of begin() and end() before allocation and use them + to state an unreachable condition. + * testsuite/23_containers/vector/bool/capacity/110498.cc: New + test. + +Reviewed-by: Tomasz KamiƄski + +(cherry picked from commit aa3aaf2bfb8fcc17076993df4297597b68bc5f60) +--- + libstdc++-v3/include/bits/vector.tcc | 5 ++++- + .../vector/bool/capacity/110498.cc | 18 ++++++++++++++++++ + 2 files changed, 22 insertions(+), 1 deletion(-) + create mode 100644 libstdc++-v3/testsuite/23_containers/vector/bool/capacity/110498.cc + +diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc +index dafc2a31a8b..c59c15beacd 100644 +--- a/libstdc++-v3/include/bits/vector.tcc ++++ b/libstdc++-v3/include/bits/vector.tcc +@@ -1059,9 +1059,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER + vector:: + _M_reallocate(size_type __n) + { ++ const iterator __begin = begin(), __end = end(); ++ if (size_type(__end - __begin) > __n) ++ __builtin_unreachable(); + _Bit_pointer __q = this->_M_allocate(__n); + iterator __start(std::__addressof(*__q), 0); +- iterator __finish(_M_copy_aligned(begin(), end(), __start)); ++ iterator __finish(_M_copy_aligned(__begin, __end, __start)); + this->_M_deallocate(); + this->_M_impl._M_start = __start; + this->_M_impl._M_finish = __finish; +diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/110498.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/110498.cc +new file mode 100644 +index 00000000000..d2d09e10d19 +--- /dev/null ++++ b/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/110498.cc +@@ -0,0 +1,18 @@ ++// { dg-options "-O3 -Werror=array-bounds" } ++// { dg-do compile } ++ ++// Bug libstdc++/110498 ++// Spurious warnings stringop-overflow and array-bounds copying data as bytes ++// into vector::reserve ++ ++#include ++ ++void f(std::vector& v) ++{ ++ // Warning emitted when set to any number in the range [1,64]. ++ const std::size_t reserve_size = 30; ++ ++ v.reserve(reserve_size); ++ v.push_back(0); ++} ++ +-- +2.49.0 +