public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/98465] New: Bogus warning stringop-overread wuth -std=gnu++20 -O2 and std::string::insert
@ 2020-12-28 18:36 romain.geissler at amadeus dot com
  2020-12-28 20:54 ` [Bug middle-end/98465] " msebor at gcc dot gnu.org
                   ` (42 more replies)
  0 siblings, 43 replies; 44+ messages in thread
From: romain.geissler at amadeus dot com @ 2020-12-28 18:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98465
           Summary: Bogus warning stringop-overread wuth -std=gnu++20 -O2
                    and std::string::insert
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: romain.geissler at amadeus dot com
  Target Milestone: ---

Hi,

The following C++ code compiled with -std=gnu++20 -O2 -Werror=stringop-overread
emits a bogus warning/error with gcc trunk, while it works without problem when
using gnu++17 instead. Tested on compiler explorer on x64 Linux:

#include <string>

const char constantString[] = {42, 53};

void f(std::string& s)
{
    s.insert(0, static_cast<const char*>(constantString), 2);
}



In file included from
/opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/string:40,
                 from <source>:1:
In static member function 'static constexpr std::char_traits<char>::char_type*
std::char_traits<char>::copy(std::char_traits<char>::char_type*, const
char_type*, std::size_t)',
    inlined from 'static void std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::_S_copy(_CharT*, const _CharT*, std::__cxx11::basic_string<_CharT,
_Traits, _Alloc>::size_type) [with _CharT = char; _Traits =
std::char_traits<char>; _Alloc = std::allocator<char>]' at
/opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/bits/basic_string.h:351:21,
    inlined from 'static void std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::_S_copy(_CharT*, const _CharT*, std::__cxx11::basic_string<_CharT,
_Traits, _Alloc>::size_type) [with _CharT = char; _Traits =
std::char_traits<char>; _Alloc = std::allocator<char>]' at
/opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/bits/basic_string.h:346:7,
    inlined from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&
std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::_M_replace(std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::size_type, std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::size_type, const _CharT*, std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>;
_Alloc = std::allocator<char>]' at
/opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/bits/basic_string.tcc:481:20,
    inlined from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&
std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::replace(std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::size_type, std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::size_type, const _CharT*, std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>;
_Alloc = std::allocator<char>]' at
/opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/bits/basic_string.h:1946:19,
    inlined from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&
std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::insert(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type,
const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type)
[with _CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>]' at
/opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/bits/basic_string.h:1693:29,
    inlined from 'void f(std::string&)' at <source>:7:60:
/opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/bits/char_traits.h:402:56:
error: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' reading
2 bytes from a region of size 0 [-Werror=stringop-overread]
  402 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2,
__n));
      |                                       
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
<source>: In function 'void f(std::string&)':
<source>:3:12: note: at offset 2 into source object 'constantString' of size 2
    3 | const char constantString[] = {42, 53};
      |            ^~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors
Compiler returned: 1


Note that gcc 10 doesn't issue any warning even with -Wall -Wextra with
gnu++20.

Cheers,
Romain

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

end of thread, other threads:[~2022-02-17 10:37 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-28 18:36 [Bug middle-end/98465] New: Bogus warning stringop-overread wuth -std=gnu++20 -O2 and std::string::insert romain.geissler at amadeus dot com
2020-12-28 20:54 ` [Bug middle-end/98465] " msebor at gcc dot gnu.org
2020-12-30 12:49 ` romain.geissler at amadeus dot com
2020-12-30 13:22 ` romain.geissler at amadeus dot com
2020-12-30 21:25 ` msebor at gcc dot gnu.org
2021-01-06 22:38 ` msebor at gcc dot gnu.org
2021-01-06 22:59 ` msebor at gcc dot gnu.org
2021-01-06 23:14 ` msebor at gcc dot gnu.org
2021-01-07 20:26 ` msebor at gcc dot gnu.org
2021-01-13 18:19 ` msebor at gcc dot gnu.org
2021-01-13 18:41 ` law at redhat dot com
2021-01-13 18:52 ` jakub at gcc dot gnu.org
2021-01-13 19:02 ` msebor at gcc dot gnu.org
2021-01-13 19:14 ` jakub at gcc dot gnu.org
2021-01-13 19:30 ` msebor at gcc dot gnu.org
2021-01-14  2:21 ` msebor at gcc dot gnu.org
2021-01-19 19:00 ` msebor at gcc dot gnu.org
2021-01-20 23:20 ` [Bug middle-end/98465] [11 Regression] Bogus -Wstringop-overread with " msebor at gcc dot gnu.org
2021-02-04 14:03 ` jakub at gcc dot gnu.org
2021-02-04 14:39 ` redi at gcc dot gnu.org
2021-02-04 15:25 ` jakub at gcc dot gnu.org
2021-02-04 15:53 ` redi at gcc dot gnu.org
2021-02-04 15:54 ` redi at gcc dot gnu.org
2021-02-04 16:02 ` msebor at gcc dot gnu.org
2021-02-04 16:58 ` jakub at gcc dot gnu.org
2021-02-04 17:12 ` jakub at gcc dot gnu.org
2021-02-04 20:57 ` msebor at gcc dot gnu.org
2021-02-04 21:09 ` jakub at gcc dot gnu.org
2021-02-05 10:15 ` jakub at gcc dot gnu.org
2021-02-08 18:51 ` jakub at gcc dot gnu.org
2021-02-09 11:33 ` cvs-commit at gcc dot gnu.org
2021-02-09 11:35 ` [Bug middle-end/98465] " jakub at gcc dot gnu.org
2021-02-19 23:41 ` msebor at gcc dot gnu.org
2021-11-12 19:53 ` msebor at gcc dot gnu.org
2022-02-15  3:55 ` Randy at miningrigrentals dot com
2022-02-15  9:47 ` redi at gcc dot gnu.org
2022-02-15  9:55 ` Randy at miningrigrentals dot com
2022-02-15 10:02 ` redi at gcc dot gnu.org
2022-02-15 10:50 ` Randy at miningrigrentals dot com
2022-02-15 12:29 ` redi at gcc dot gnu.org
2022-02-15 12:40 ` Randy at miningrigrentals dot com
2022-02-15 12:52 ` redi at gcc dot gnu.org
2022-02-15 19:23 ` Randy at miningrigrentals dot com
2022-02-17 10:37 ` redi at gcc dot gnu.org

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).