public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/110498] New: Spurious warnings stringop-overflow and array-bounds copying data as bytes into vector::reserve
@ 2023-06-30 12:21 rogerio.souza at gmail dot com
  2024-04-02 20:20 ` [Bug tree-optimization/110498] " michael.ragazzon at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: rogerio.souza at gmail dot com @ 2023-06-30 12:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110498

            Bug ID: 110498
           Summary: Spurious warnings stringop-overflow and array-bounds
                    copying data as bytes into vector::reserve
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Keywords: diagnostic, missed-optimization
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rogerio.souza at gmail dot com
  Target Milestone: ---

Created attachment 55432
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55432&action=edit
This is the preprocessed file (*.i*) that triggers the warning reported here.

The warning issue happens when using GCC v13.1.0 on Red Hat 7.9
3.10.0-1160.90.1.el7.x86_64.

The compiler configuration settings are:

/grid/common/test/gcc-v13.1.0d1rh74_lnx86/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/grid/common/test/gcc-v13.1.0d1rh74_lnx86/bin/gcc
COLLECT_LTO_WRAPPER=/grid/common/test/gcc-v13.1.0d1rh74_lnx86/libexec/gcc/x86_64-redhat-linux/13.1.0/lto-wrapper
Target: x86_64-redhat-linux
Configured with: /tmp/gcc-v13.1.0d1rh74_lnx86/gcc.source/configure
--prefix=/grid/common/test/gcc-v13.1.0d1rh74_lnx86 --with-pkgversion=Cadence
--disable-libgcj --enable-threads=posix --enable-shared --with-system-zlib
--enable-checking=release --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-languages=c,c++,fortran --disable-nls --enable-gnu-unique-object
--enable-bootstrap --enable-plugin --enable-linker-build-id
--enable-gnu-indirect-function --enable-install-libiberty --with-tune=generic
--enable-initfini-array --enable-multiarch --with-linker-hash-style=gnu
--with-ld=/grid/common/test/gcc-v13.1.0d1rh74_lnx86/bin/ld
--with-as=/grid/common/test/gcc-v13.1.0d1rh74_lnx86/bin/as
--build=x86_64-redhat-linux --host=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.1.0 (Cadence)

=========================================================

The command line to reproduce the warning and the compiler output:

/opt/gcc-v13.1.0d1rh74_lnx86/bin/gcc -c -fpic  -std=c++2b -pthread
-D_GLIBCXX_USE_CXX11_ABI=1 -Wstrict-aliasing=3 -O3 -Wall -Werror -DNDEBUG
-Wstrict-aliasing=3  -Wextra   -DET7 -DETX=7
-DCMG_QT_VERSION='"MAIN_WXE_23.05.539.d000-Z2, VEngineering"'  -DLINUX2   
-I/opt/ua/3party/capnproto -I/opt/ua/Framework -I. -I.. -I/opt/ap/include
-I/grid/cva/p4/eugene/gcc_wxe/ua/include -I/opt/ua/3party/xlm_inst/include 
-MMD ../radbSerializer.C

In file included from
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/string:51,
                 from
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/stdexcept:39,
                 from ../radbSerializer.C:9:
In static member function 'static constexpr _Up* std::__copy_move<_IsMove,
true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp =
long unsigned int; _Up = long unsigned int; bool _IsMove = false]',
    inlined from 'constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bool
_IsMove = false; _II = long unsigned int*; _OI = long unsigned int*]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_algobase.h:506:3 ,
    inlined from 'constexpr _OI std::__copy_move_a1(_II, _II, _OI) [with bool
_IsMove = false; _II = long unsigned int*; _OI = long unsigned int*]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_algobase.h:533:4 ,
    inlined from 'constexpr _OI std::__copy_move_a(_II, _II, _OI) [with bool
_IsMove = false; _II = long unsigned int*; _OI = long unsigned int*]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_algobase.h:540:31,   
inlined from 'constexpr _OI std::copy(_II, _II, _OI) [with _II = long unsigned
int*; _OI = long unsigned int*]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_algobase.h:633:7,
    inlined from 'constexpr std::vector<bool, _Alloc>::iterator
std::vector<bool, _Alloc>::_M_copy_aligned(const_iterator, const_iterator,
iterator) [with _Alloc = std::allocator<bool>]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_bvector.h:1303:28,
    inlined from 'constexpr void std::vector<bool,
_Alloc>::_M_reallocate(size_type) [with _Alloc = std::allocator<bool>]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/vector.tcc:851:40,
    inlined from 'constexpr void std::vector<bool, _Alloc>::reserve(size_type)
[with _Alloc = std::allocator<bool>]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_bvector.h:1091:17,
    inlined from 'radb::ScopesSerializer::ScopesSerializer()' at
../radbSerializer.C:25:24:
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_algobase.h:437:30:
error: 'void* __builtin_memmove(void*, const void*, long unsigned int)' forming
offset 8 is out of the bounds [0, 8] [-Werror=array-bounds=]
  437 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In static member function 'static constexpr _Up* std::__copy_move<_IsMove,
true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp =
long unsigned int; _Up = long unsigned int; bool _IsMove = false]',
    inlined from 'constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bool
_IsMove = false; _II = long unsigned int*; _OI = long unsigned int*]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_algobase.h:506:3 ,
    inlined from 'constexpr _OI std::__copy_move_a1(_II, _II, _OI) [with bool
_IsMove = false; _II = long unsigned int*; _OI = long unsigned int*]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_algobase.h:533:4 ,
    inlined from 'constexpr _OI std::__copy_move_a(_II, _II, _OI) [with bool
_IsMove = false; _II = long unsigned int*; _OI = long unsigned int*]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_algobase.h:540:31,   
inlined from 'constexpr _OI std::copy(_II, _II, _OI) [with _II = long unsigned
int*; _OI = long unsigned int*]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_algobase.h:633:7,
    inlined from 'constexpr std::vector<bool, _Alloc>::iterator
std::vector<bool, _Alloc>::_M_copy_aligned(const_iterator, const_iterator,
iterator) [with _Alloc = std::allocator<bool>]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_bvector.h:1303:28,
    inlined from 'constexpr void std::vector<bool,
_Alloc>::_M_reallocate(size_type) [with _Alloc = std::allocator<bool>]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/vector.tcc:851:40,
    inlined from 'constexpr void std::vector<bool, _Alloc>::reserve(size_type)
[with _Alloc = std::allocator<bool>]' at
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_bvector.h:1091:17,
    inlined from 'radb::VarsSerializer::VarsSerializer()' at
../radbSerializer.C:93:27:
/opt/gcc-v13.1.0d1rh74_lnx86/include/c++/13.1.0/bits/stl_algobase.h:437:30:
error: 'void* __builtin_memmove(void*, const void*, long unsigned int)' forming
offset 8 is out of the bounds [0, 8] [-Werror=array-bounds=]
  437 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors

=========================================================

The the preprocessed file "radbSerializer.ii" is attached. This might means
that this issue was still not totally fixed on GCC v13.1.0

Regards,
Rogerio

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/110498] Spurious warnings stringop-overflow and array-bounds copying data as bytes into vector::reserve
  2023-06-30 12:21 [Bug libstdc++/110498] New: Spurious warnings stringop-overflow and array-bounds copying data as bytes into vector::reserve rogerio.souza at gmail dot com
@ 2024-04-02 20:20 ` michael.ragazzon at gmail dot com
  2024-04-02 20:24 ` pinskia at gcc dot gnu.org
  2024-04-02 20:41 ` michael.ragazzon at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: michael.ragazzon at gmail dot com @ 2024-04-02 20:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110498

Michael Ragazzon <michael.ragazzon at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |michael.ragazzon at gmail dot com

--- Comment #1 from Michael Ragazzon <michael.ragazzon at gmail dot com> ---
I seem to also have encountered this issue while using `std::vector<bool>`.
Here is a relatively small reproducer.

Compile with: -O3 -std=c++17 -Wall -Werror

---

#include <stdio.h>
#include <vector>

class Testing {
public:
        Testing();

private:
        std::vector<bool> elements;
};

Testing::Testing()
{
        // Warning emitted when set to any number in the range [1,64].
        constexpr size_t reserve_size = 30;

        elements.reserve(reserve_size);
        elements.push_back(0);
}

int main() {
    Testing testing;
}

---

https://godbolt.org/z/eG66sjsPq

This issue seems to have started with GCC 13.1, and exists also on current
trunk (tested on Compiler Explorer).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/110498] Spurious warnings stringop-overflow and array-bounds copying data as bytes into vector::reserve
  2023-06-30 12:21 [Bug libstdc++/110498] New: Spurious warnings stringop-overflow and array-bounds copying data as bytes into vector::reserve rogerio.souza at gmail dot com
  2024-04-02 20:20 ` [Bug tree-optimization/110498] " michael.ragazzon at gmail dot com
@ 2024-04-02 20:24 ` pinskia at gcc dot gnu.org
  2024-04-02 20:41 ` michael.ragazzon at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-02 20:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110498

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Michael Ragazzon from comment #1)
> I seem to also have encountered this issue while using `std::vector<bool>`.
> Here is a relatively small reproducer.

std::vector<bool> is a different issue and filed as PR 111118.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/110498] Spurious warnings stringop-overflow and array-bounds copying data as bytes into vector::reserve
  2023-06-30 12:21 [Bug libstdc++/110498] New: Spurious warnings stringop-overflow and array-bounds copying data as bytes into vector::reserve rogerio.souza at gmail dot com
  2024-04-02 20:20 ` [Bug tree-optimization/110498] " michael.ragazzon at gmail dot com
  2024-04-02 20:24 ` pinskia at gcc dot gnu.org
@ 2024-04-02 20:41 ` michael.ragazzon at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: michael.ragazzon at gmail dot com @ 2024-04-02 20:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110498

--- Comment #3 from Michael Ragazzon <michael.ragazzon at gmail dot com> ---
(In reply to Andrew Pinski from comment #2)
> std::vector<bool> is a different issue and filed as PR 111118.

Thanks for pointing me in the right direction. I believe the warnings in the
description points to vector<bool> being used here as well. Perhaps they are
duplicates?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-02 20:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-30 12:21 [Bug libstdc++/110498] New: Spurious warnings stringop-overflow and array-bounds copying data as bytes into vector::reserve rogerio.souza at gmail dot com
2024-04-02 20:20 ` [Bug tree-optimization/110498] " michael.ragazzon at gmail dot com
2024-04-02 20:24 ` pinskia at gcc dot gnu.org
2024-04-02 20:41 ` michael.ragazzon at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).