From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4EC7E3858D37; Tue, 9 May 2023 16:48:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4EC7E3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683650922; bh=XQldRm1hGxzdRHrI6RyRmK0Kn16liX71LmEZX7GqNzA=; h=From:To:Subject:Date:From; b=JIOST0oHkSXdnPLBClo+PdkfR7Lr2hP0CGWhUj6qOHTkJ71HvW1uYdwEfkir5ydWW KjU/zk7BzWthA0gEadP6/mQKh+n7vFhgU9TMWFoBVbX5bKFlvnQwRfRXfL89jT2j3e HJBkpx3SBm72P8GLs//wQveSlQwxJhh3ggvKM0Gc= From: "szhong at perforce dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109791] New: -Wstringop-overflow warning with -O3 and _GLIBCXX_USE_CXX11_ABI=0 Date: Tue, 09 May 2023 16:48:41 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: szhong at perforce dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109791 Bug ID: 109791 Summary: -Wstringop-overflow warning with -O3 and _GLIBCXX_USE_CXX11_ABI=3D0 Product: gcc Version: 12.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: szhong at perforce dot com Target Milestone: --- Created attachment 55033 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D55033&action=3Dedit preprocessed file It appears -fvect-cost-model=3Ddynamic from the -O3 flag is causing the -Wstringop-overflow warning. testcase: #include #include int main() { char str[] =3D " a"; do { std::string input(str, sizeof(str) / sizeof(*str)); } while (std::next_permutation(str, str + sizeof(str) / sizeof(*str))); return 0; } $ g++ -v -save-temps -m64 -D_GLIBCXX_USE_CXX11_ABI=3D0 -O2 -fvect-cost-model=3Ddynamic no_cxx11_abi.cpp Using built-in specs. COLLECT_GCC=3Dg++ COLLECT_LTO_WRAPPER=3D/opt/rh/gcc-toolset-12/root/usr/libexec/gcc/x86_64-re= dhat-linux/12/lto-wrapper OFFLOAD_TARGET_NAMES=3Dnvptx-none OFFLOAD_TARGET_DEFAULT=3D1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=3Dc,c++,fortran,lto --prefix=3D/opt/rh/gcc-toolset-12/ro= ot/usr --mandir=3D/opt/rh/gcc-toolset-12/root/usr/share/man --infodir=3D/opt/rh/gcc-toolset-12/root/usr/share/info --with-bugurl=3Dhttp://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=3Dposix --enable-checking=3Drelease --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-linker-hash-style=3Dgnu --enable-plugin --enable-initfini-array --with-isl=3D/builddir/build/BUILD/gcc-12.1.1-20220628/obj-x86_64-redhat-li= nux/isl-install --enable-offload-targets=3Dnvptx-none --without-cuda-driver --enable-offload-defaulted --enable-gnu-indirect-function --enable-cet --with-tune=3Dgeneric --with-arch_64=3Dx86-64-v2 --with-arch_32=3Dx86-64 --build=3Dx86_64-redhat-linux --with-build-config=3Dbootstrap-lto --enable-link-serialization=3D1 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.1.1 20220628 (Red Hat 12.1.1-3) (GCC)=20 COLLECT_GCC_OPTIONS=3D'-v' '-save-temps' '-m64' '-D' '_GLIBCXX_USE_CXX11_AB= I=3D0' '-O2' '-fvect-cost-model=3Ddynamic' '-shared-libgcc' '-mtune=3Dgeneric' '-march=3Dx86-64-v2' '-dumpdir' 'a-' /opt/rh/gcc-toolset-12/root/usr/libexec/gcc/x86_64-redhat-linux/12/cc1plus= -E -quiet -v -D_GNU_SOURCE -D _GLIBCXX_USE_CXX11_ABI=3D0 no_cxx11_abi.cpp -m64 -mtune=3Dgeneric -march=3Dx86-64-v2 -fvect-cost-model=3Ddynamic -O2 -fpch-p= reprocess -o a-no_cxx11_abi.ii ignoring nonexistent directory "/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/include-fix= ed" ignoring nonexistent directory "/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../..= /x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../= include/c++/12 /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../= include/c++/12/x86_64-redhat-linux /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../= include/c++/12/backward /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/include /usr/local/include /opt/rh/gcc-toolset-12/root/usr/include /usr/include End of search list. COLLECT_GCC_OPTIONS=3D'-v' '-save-temps' '-m64' '-D' '_GLIBCXX_USE_CXX11_AB= I=3D0' '-O2' '-fvect-cost-model=3Ddynamic' '-shared-libgcc' '-mtune=3Dgeneric' '-march=3Dx86-64-v2' '-dumpdir' 'a-' /opt/rh/gcc-toolset-12/root/usr/libexec/gcc/x86_64-redhat-linux/12/cc1plus -fpreprocessed a-no_cxx11_abi.ii -quiet -dumpdir a- -dumpbase no_cxx11_abi.= cpp -dumpbase-ext .cpp -m64 -mtune=3Dgeneric -march=3Dx86-64-v2 -O2 -version -fvect-cost-model=3Ddynamic -o a-no_cxx11_abi.s GNU C++17 (GCC) version 12.1.1 20220628 (Red Hat 12.1.1-3) (x86_64-redhat-linux) compiled by GNU C version 12.1.1 20220628 (Red Hat 12.1.1-3), GMP version 6.2.0, MPFR version 4.1.0-p9, MPC version 1.2.1, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=3D100 --param ggc-min-heapsize=3D131= 072 GNU C++17 (GCC) version 12.1.1 20220628 (Red Hat 12.1.1-3) (x86_64-redhat-linux) compiled by GNU C version 12.1.1 20220628 (Red Hat 12.1.1-3), GMP version 6.2.0, MPFR version 4.1.0-p9, MPC version 1.2.1, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=3D100 --param ggc-min-heapsize=3D131= 072 Compiler executable checksum: 4fe953bdd6603241811586d9fd73a7cb In file included from /opt/rh/gcc-toolset-12/root/usr/include/c++/12/bits/stl_pair.h:61, from /opt/rh/gcc-toolset-12/root/usr/include/c++/12/bits/stl_algobase.h:64, from /opt/rh/gcc-toolset-12/root/usr/include/c++/12/algorithm:60, from no_cxx11_abi.cpp:1: In function \u2018std::_Require >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_= Tp&, _Tp&) [with _Tp =3D char]\u2019, inlined from \u2018void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 =3D char*; _ForwardIterator2 =3D char*]\u2019 at /opt/rh/gcc-toolset-12/root/usr/include/c++/12/bits/stl_algobase.h:182:11, inlined from \u2018void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, random_access_iterator_tag) [with _RandomAccessItera= tor =3D char*]\u2019 at /opt/rh/gcc-toolset-12/root/usr/include/c++/12/bits/stl_algo.h:1107:18, inlined from \u2018bool std::__next_permutation(_BidirectionalIterator, _BidirectionalIterator, _Compare) [with _BidirectionalIterator =3D char*; _Compare =3D __gnu_cxx::__ops::_Iter_less_iter]\u2019 at /opt/rh/gcc-toolset-12/root/usr/include/c++/12/bits/stl_algo.h:2907:22, inlined from \u2018bool std::next_permutation(_BIter, _BIter) [with _BI= ter =3D char*]\u2019 at /opt/rh/gcc-toolset-12/root/usr/include/c++/12/bits/stl_algo.h:2947:2, inlined from \u2018int main()\u2019 at no_cxx11_abi.cpp:10:33: /opt/rh/gcc-toolset-12/root/usr/include/c++/12/bits/move.h:205:11: warning: writing 8 bytes into a region of size 2 [-Wstringop-overflow=3D] 205 | __a =3D _GLIBCXX_MOVE(__b); | ~~~~^~~~~~~~~~~~~~~~ no_cxx11_abi.cpp: In function \u2018int main()\u2019: no_cxx11_abi.cpp:6:10: note: at offset [1, 2] into destination object \u2018str\u2019 of size 3 6 | char str[] =3D " a"; | ^~~ no_cxx11_abi.cpp:6:10: note: at offset [2, 3] into destination object \u2018str\u2019 of size 3 In function \u2018std::_Require >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_= Tp&, _Tp&) [with _Tp =3D char]\u2019, inlined from \u2018void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 =3D char*; _ForwardIterator2 =3D char*]\u2019 at /opt/rh/gcc-toolset-12/root/usr/include/c++/12/bits/stl_algobase.h:182:11, inlined from \u2018void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, random_access_iterator_tag) [with _RandomAccessItera= tor =3D char*]\u2019 at /opt/rh/gcc-toolset-12/root/usr/include/c++/12/bits/stl_algo.h:1107:18, inlined from \u2018bool std::__next_permutation(_BidirectionalIterator, _BidirectionalIterator, _Compare) [with _BidirectionalIterator =3D char*; _Compare =3D __gnu_cxx::__ops::_Iter_less_iter]\u2019 at /opt/rh/gcc-toolset-12/root/usr/include/c++/12/bits/stl_algo.h:2907:22, inlined from \u2018bool std::next_permutation(_BIter, _BIter) [with _BI= ter =3D char*]\u2019 at /opt/rh/gcc-toolset-12/root/usr/include/c++/12/bits/stl_algo.h:2947:2, inlined from \u2018int main()\u2019 at no_cxx11_abi.cpp:10:33: /opt/rh/gcc-toolset-12/root/usr/include/c++/12/bits/move.h:206:11: warning: writing 8 bytes into a region of size 0 [-Wstringop-overflow=3D] 206 | __b =3D _GLIBCXX_MOVE(__tmp); | ~~~~^~~~~~~~~~~~~~~~~~ no_cxx11_abi.cpp: In function \u2018int main()\u2019: no_cxx11_abi.cpp:6:10: note: at offset 9223372036854775803 into destination object \u2018str\u2019 of size 3 6 | char str[] =3D " a"; | ^~~ COLLECT_GCC_OPTIONS=3D'-v' '-save-temps' '-m64' '-D' '_GLIBCXX_USE_CXX11_AB= I=3D0' '-O2' '-fvect-cost-model=3Ddynamic' '-shared-libgcc' '-mtune=3Dgeneric' '-march=3Dx86-64-v2' '-dumpdir' 'a-' as -v --64 -o a-no_cxx11_abi.o a-no_cxx11_abi.s GNU assembler version 2.38 (x86_64-redhat-linux) using BFD version version 2.38-16.el9 COMPILER_PATH=3D/opt/rh/gcc-toolset-12/root/usr/libexec/gcc/x86_64-redhat-l= inux/12/:/opt/rh/gcc-toolset-12/root/usr/libexec/gcc/x86_64-redhat-linux/12= /:/opt/rh/gcc-toolset-12/root/usr/libexec/gcc/x86_64-redhat-linux/:/opt/rh/= gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/:/opt/rh/gcc-toolset= -12/root/usr/lib/gcc/x86_64-redhat-linux/ LIBRARY_PATH=3D/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/= 12/:/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../..= /../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/opt/rh/gcc-toolset-12/root/us= r/lib/gcc/x86_64-redhat-linux/12/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS=3D'-v' '-save-temps' '-m64' '-D' '_GLIBCXX_USE_CXX11_AB= I=3D0' '-O2' '-fvect-cost-model=3Ddynamic' '-shared-libgcc' '-mtune=3Dgeneric' '-march=3Dx86-64-v2' '-dumpdir' 'a.' /opt/rh/gcc-toolset-12/root/usr/libexec/gcc/x86_64-redhat-linux/12/collect2 -plugin /opt/rh/gcc-toolset-12/root/usr/libexec/gcc/x86_64-redhat-linux/12/liblto_p= lugin.so -plugin-opt=3D/opt/rh/gcc-toolset-12/root/usr/libexec/gcc/x86_64-redhat-lin= ux/12/lto-wrapper -plugin-opt=3D-fresolution=3Da.res -plugin-opt=3D-pass-through=3D-lgcc_s -plugin-opt=3D-pass-through=3D-lgcc -plugin-opt=3D-pass-through=3D-lc -plugin-opt=3D-pass-through=3D-lgcc_s -plugin-opt=3D-pass-through=3D-lgcc -= -build-id --no-add-needed --eh-frame-hdr --hash-style=3Dgnu -m elf_x86_64 -dynamic-li= nker /lib64/ld-linux-x86-64.so.2 /lib/../lib64/crt1.o /lib/../lib64/crti.o /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/crtbegin.o -L/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12 -L/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../.= ./lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../.. a-no_cxx11_abi.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/crtend.o /lib/../lib64/crtn.o COLLECT_GCC_OPTIONS=3D'-v' '-save-temps' '-m64' '-D' '_GLIBCXX_USE_CXX11_AB= I=3D0' '-O2' '-fvect-cost-model=3Ddynamic' '-shared-libgcc' '-mtune=3Dgeneric' '-march=3Dx86-64-v2' '-dumpdir' 'a.' $ cat /etc/os-release NAME=3D"Red Hat Enterprise Linux" VERSION=3D"9.1 (Plow)" ID=3D"rhel" ID_LIKE=3D"fedora" VERSION_ID=3D"9.1" PLATFORM_ID=3D"platform:el9" PRETTY_NAME=3D"Red Hat Enterprise Linux 9.1 (Plow)" ANSI_COLOR=3D"0;31" LOGO=3D"fedora-logo-icon" CPE_NAME=3D"cpe:/o:redhat:enterprise_linux:9::baseos" HOME_URL=3D"https://www.redhat.com/" DOCUMENTATION_URL=3D"https://access.redhat.com/documentation/red_hat_enterp= rise_linux/9/" BUG_REPORT_URL=3D"https://bugzilla.redhat.com/" REDHAT_BUGZILLA_PRODUCT=3D"Red Hat Enterprise Linux 9" REDHAT_BUGZILLA_PRODUCT_VERSION=3D9.1 REDHAT_SUPPORT_PRODUCT=3D"Red Hat Enterprise Linux" REDHAT_SUPPORT_PRODUCT_VERSION=3D"9.1"=