https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109791
Bug ID: 109791 Summary: -Wstringop-overflow warning with -O3 and _GLIBCXX_USE_CXX11_ABI=0 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=55033&action=edit preprocessed file It appears -fvect-cost-model=dynamic from the -O3 flag is causing the -Wstringop-overflow warning. testcase: #include <algorithm> #include <string> int main() { char str[] = " 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=0 -O2 -fvect-cost-model=dynamic no_cxx11_abi.cpp Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/opt/rh/gcc-toolset-12/root/usr/libexec/gcc/x86_64-redhat-linux/12/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/gcc-toolset-12/root/usr --mandir=/opt/rh/gcc-toolset-12/root/usr/share/man --infodir=/opt/rh/gcc-toolset-12/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --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=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-12.1.1-20220628/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-offload-defaulted --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_64=x86-64-v2 --with-arch_32=x86-64 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.1.1 20220628 (Red Hat 12.1.1-3) (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-m64' '-D' '_GLIBCXX_USE_CXX11_ABI=0' '-O2' '-fvect-cost-model=dynamic' '-shared-libgcc' '-mtune=generic' '-march=x86-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=0 no_cxx11_abi.cpp -m64 -mtune=generic -march=x86-64-v2 -fvect-cost-model=dynamic -O2 -fpch-preprocess -o a-no_cxx11_abi.ii ignoring nonexistent directory "/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/include-fixed" 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='-v' '-save-temps' '-m64' '-D' '_GLIBCXX_USE_CXX11_ABI=0' '-O2' '-fvect-cost-model=dynamic' '-shared-libgcc' '-mtune=generic' '-march=x86-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=generic -march=x86-64-v2 -O2 -version -fvect-cost-model=dynamic -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=100 --param ggc-min-heapsize=131072 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=100 --param ggc-min-heapsize=131072 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::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = char]\u2019, inlined from \u2018void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = char*; _ForwardIterator2 = 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 _RandomAccessIterator = 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 = char*; _Compare = __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 _BIter = 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=] 205 | __a = _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[] = " 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::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = char]\u2019, inlined from \u2018void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = char*; _ForwardIterator2 = 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 _RandomAccessIterator = 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 = char*; _Compare = __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 _BIter = 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=] 206 | __b = _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[] = " a"; | ^~~ COLLECT_GCC_OPTIONS='-v' '-save-temps' '-m64' '-D' '_GLIBCXX_USE_CXX11_ABI=0' '-O2' '-fvect-cost-model=dynamic' '-shared-libgcc' '-mtune=generic' '-march=x86-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=/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/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=/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/usr/lib/gcc/x86_64-redhat-linux/12/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-save-temps' '-m64' '-D' '_GLIBCXX_USE_CXX11_ABI=0' '-O2' '-fvect-cost-model=dynamic' '-shared-libgcc' '-mtune=generic' '-march=x86-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_plugin.so -plugin-opt=/opt/rh/gcc-toolset-12/root/usr/libexec/gcc/x86_64-redhat-linux/12/lto-wrapper -plugin-opt=-fresolution=a.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /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='-v' '-save-temps' '-m64' '-D' '_GLIBCXX_USE_CXX11_ABI=0' '-O2' '-fvect-cost-model=dynamic' '-shared-libgcc' '-mtune=generic' '-march=x86-64-v2' '-dumpdir' 'a.' $ cat /etc/os-release NAME="Red Hat Enterprise Linux" VERSION="9.1 (Plow)" ID="rhel" ID_LIKE="fedora" VERSION_ID="9.1" PLATFORM_ID="platform:el9" PRETTY_NAME="Red Hat Enterprise Linux 9.1 (Plow)" ANSI_COLOR="0;31" LOGO="fedora-logo-icon" CPE_NAME="cpe:/o:redhat:enterprise_linux:9::baseos" HOME_URL="https://www.redhat.com/" DOCUMENTATION_URL="https://access.redhat.com/documentation/red_hat_enterprise_linux/9/" BUG_REPORT_URL="https://bugzilla.redhat.com/" REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 9" REDHAT_BUGZILLA_PRODUCT_VERSION=9.1 REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux" REDHAT_SUPPORT_PRODUCT_VERSION="9.1"