public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/106044] New: Spurious warning: -Wrestrict for adding std::strings (__builtin_memcpy)
@ 2022-06-21 12:24 cuzdav at gmail dot com
2022-06-21 12:27 ` [Bug tree-optimization/106044] " cuzdav at gmail dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: cuzdav at gmail dot com @ 2022-06-21 12:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106044
Bug ID: 106044
Summary: Spurious warning: -Wrestrict for adding std::strings
(__builtin_memcpy)
Product: gcc
Version: 12.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: cuzdav at gmail dot com
Target Milestone: ---
Created attachment 53182
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53182&action=edit
preprocessed code
At optimization O3, beginning in g++ 12.1 (and still present in trunk) with
-Wrestrict enabled I see the following warning:
warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)'
accessing 9223372036854775810 or more bytes at offsets [2, 9223372036854775807]
and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Wrestrict]
Here is the code:
///////////////////////////////////////
#include <string>
std::string f(std::size_t n) {
return "_" + std::to_string(n);
}
///////////////////////////////////////
On Compiler explorer: https://godbolt.org/z/KMWehnscM
Command line:
g++12 -O3 --std=c++20 -Wrestrict source.cpp
Output:
In file included from
/opt/compiler-explorer/gcc-trunk-20220621/include/c++/13.0.0/string:40,
from <source>:1:
In static member function 'static constexpr std::char_traits<char>::char_type*
std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)',
inlined from 'static constexpr void std::__cxx11::basic_string<_CharT,
_Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT =
char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' at
/opt/compiler-explorer/gcc-trunk-20220621/include/c++/13.0.0/bits/basic_string.h:423:21,
inlined from 'constexpr std::__cxx11::basic_string<_CharT, _Traits,
_Allocator>& std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::_M_replace(size_type, size_type, const _CharT*, size_type) [with
_CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>]' at
/opt/compiler-explorer/gcc-trunk-20220621/include/c++/13.0.0/bits/basic_string.tcc:532:22,
inlined from 'constexpr std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>& std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>::replace(size_type, size_type, const _CharT*, size_type) [with _CharT =
char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' at
/opt/compiler-explorer/gcc-trunk-20220621/include/c++/13.0.0/bits/basic_string.h:2171:19,
inlined from 'constexpr std::__cxx11::basic_string<_CharT, _Traits,
_Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::insert(size_type,
const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>]' at
/opt/compiler-explorer/gcc-trunk-20220621/include/c++/13.0.0/bits/basic_string.h:1928:22,
inlined from 'constexpr std::__cxx11::basic_string<_CharT, _Traits,
_Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT,
_Traits, _Allocator>&&) [with _CharT = char; _Traits = char_traits<char>;
_Alloc = allocator<char>]' at
/opt/compiler-explorer/gcc-trunk-20220621/include/c++/13.0.0/bits/basic_string.h:3594:36,
inlined from 'std::string f(std::size_t)' at <source>:4:34:
/opt/compiler-explorer/gcc-trunk-20220621/include/c++/13.0.0/bits/char_traits.h:434:56:
warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)'
accessing 9223372036854775810 or more bytes at offsets [2, 9223372036854775807]
and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Wrestrict]
434 | return static_cast<char_type*>(__builtin_memcpy(__s1, __s2,
__n));
|
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
Compiler returned: 0
//////////////////////////////////
local machine g++ output (where I first encountered it)
[cuzdav@docker tmp]$ /opt/imc/gcc-12.1.0/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/opt/imc/gcc-12.1.0/bin/g++
COLLECT_LTO_WRAPPER=/opt/imc/gcc-12.1.0/libexec/gcc/x86_64-pc-linux-gnu/12.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-12.1.0/configure --prefix=/opt/imc/gcc-12.1.0
--enable-languages=c,c++,fortran,lto --disable-multilib
--with-build-time-tools=/build/INSTALLDIR//opt/imc/gcc-12.1.0/bin
--enable-libstdcxx-time=rt
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.1.0 (GCC)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/106044] Spurious warning: -Wrestrict for adding std::strings (__builtin_memcpy)
2022-06-21 12:24 [Bug tree-optimization/106044] New: Spurious warning: -Wrestrict for adding std::strings (__builtin_memcpy) cuzdav at gmail dot com
@ 2022-06-21 12:27 ` cuzdav at gmail dot com
2022-06-21 14:51 ` cuzdav at gmail dot com
2022-06-21 17:33 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: cuzdav at gmail dot com @ 2022-06-21 12:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106044
--- Comment #1 from Chris Uzdavinis <cuzdav at gmail dot com> ---
only in c++20, too.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/106044] Spurious warning: -Wrestrict for adding std::strings (__builtin_memcpy)
2022-06-21 12:24 [Bug tree-optimization/106044] New: Spurious warning: -Wrestrict for adding std::strings (__builtin_memcpy) cuzdav at gmail dot com
2022-06-21 12:27 ` [Bug tree-optimization/106044] " cuzdav at gmail dot com
@ 2022-06-21 14:51 ` cuzdav at gmail dot com
2022-06-21 17:33 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: cuzdav at gmail dot com @ 2022-06-21 14:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106044
--- Comment #2 from Chris Uzdavinis <cuzdav at gmail dot com> ---
Even marginally simpler:
#include <string>
auto f() {
return "_" + std::string(" ");
}
Originally I marked it as tree-optimization since it's only with -O3, but it
could be an issue in the standard library itself. I didn't consider that
initially.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/106044] Spurious warning: -Wrestrict for adding std::strings (__builtin_memcpy)
2022-06-21 12:24 [Bug tree-optimization/106044] New: Spurious warning: -Wrestrict for adding std::strings (__builtin_memcpy) cuzdav at gmail dot com
2022-06-21 12:27 ` [Bug tree-optimization/106044] " cuzdav at gmail dot com
2022-06-21 14:51 ` cuzdav at gmail dot com
@ 2022-06-21 17:33 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-06-21 17:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106044
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|UNCONFIRMED |RESOLVED
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 105651.
*** This bug has been marked as a duplicate of bug 105651 ***
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-06-21 17:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-21 12:24 [Bug tree-optimization/106044] New: Spurious warning: -Wrestrict for adding std::strings (__builtin_memcpy) cuzdav at gmail dot com
2022-06-21 12:27 ` [Bug tree-optimization/106044] " cuzdav at gmail dot com
2022-06-21 14:51 ` cuzdav at gmail dot com
2022-06-21 17:33 ` pinskia 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).