public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/104336] New: bogus -Wrestrict for std::string assignment with
@ 2022-02-01 21:24 msebor at gcc dot gnu.org
  2022-02-01 21:25 ` [Bug tree-optimization/104336] " msebor at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-02-01 21:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104336
           Summary: bogus -Wrestrict for std::string assignment with
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The following false positive was reported in
https://bugzilla.redhat.com/show_bug.cgi?id=2047428.  It boils down to the same
underlying problem as in pr98465.

$ cat t.C && g++ -O2 -S -Wall -D_GLIBCXX_ASSERTIONS t.C
#include <string>

std::string s;

void f (void)
{
  s = "/";
}

In file included from
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/string:40,
                 from ../t.C:1:
In static member function ‘static std::char_traits<char>::char_type*
std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
    inlined from ‘static 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
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:423:21,
    inlined from ‘static 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
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:418:7,
    inlined from ‘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
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:532:22,
    inlined from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&
std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::assign(const _CharT*)
[with _CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>]’ at
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:1647:19,
    inlined from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&
std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*)
[with _CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>]’ at
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:815:28,
    inlined from ‘void f()’ at ../t.C:7:7:
/build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/char_traits.h:431:56:
warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’
accessing 9223372036854775810 or more bytes at offsets -4611686018427387902 and
[-4611686018427387903, 4611686018427387904] may overlap up to
9223372036854775813 bytes at offset -3 [-Wrestrict]
  431 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2,
__n));
      |                                       
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

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

* [Bug tree-optimization/104336] bogus -Wrestrict for std::string assignment with
  2022-02-01 21:24 [Bug tree-optimization/104336] New: bogus -Wrestrict for std::string assignment with msebor at gcc dot gnu.org
@ 2022-02-01 21:25 ` msebor at gcc dot gnu.org
  2022-04-25 19:11 ` mattias.ellert at physics dot uu.se
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-02-01 21:25 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
                URL|                            |https://bugzilla.redhat.com
                   |                            |/show_bug.cgi?id=2047428
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=98465
   Last reconfirmed|                            |2022-02-01
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
             Blocks|                            |84774


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84774
[Bug 84774] [meta-bug] bogus/missing -Wrestrict

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

* [Bug tree-optimization/104336] bogus -Wrestrict for std::string assignment with
  2022-02-01 21:24 [Bug tree-optimization/104336] New: bogus -Wrestrict for std::string assignment with msebor at gcc dot gnu.org
  2022-02-01 21:25 ` [Bug tree-optimization/104336] " msebor at gcc dot gnu.org
@ 2022-04-25 19:11 ` mattias.ellert at physics dot uu.se
  2022-04-25 20:26 ` amacleod at redhat dot com
  2022-05-02 12:45 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: mattias.ellert at physics dot uu.se @ 2022-04-25 19:11 UTC (permalink / raw)
  To: gcc-bugs

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

Mattias Ellert <mattias.ellert at physics dot uu.se> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mattias.ellert at physics dot uu.s
                   |                            |e

--- Comment #1 from Mattias Ellert <mattias.ellert at physics dot uu.se> ---
Created attachment 52872
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52872&action=edit
Proposed fix

Proposed fix:

``` {.diff}
--- usr/include/c++/12/bits/basic_string.tcc.orig       2022-04-14
01:23:43.000000000 +0200
+++ usr/include/c++/12/bits/basic_string.tcc    2022-04-25 16:18:57.028352162
+0200
@@ -527,10 +527,10 @@
                    }
                  else
                    {
-                     const size_type __nleft = (__p + __len1) - __s;
-                     this->_S_move(__p, __s, __nleft);
-                     this->_S_copy(__p + __nleft, __p + __len2,
-                                   __len2 - __nleft);
+                     const size_type __nleft = (__s + __len2) - (__p +
__len1);
+                     this->_S_move(__p, __s, __len2 - __nleft);
+                     this->_S_copy(__p + __len2 - __nleft, __p + __len2,
+                                   __nleft);
                    }
                }
            }
```

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

* [Bug tree-optimization/104336] bogus -Wrestrict for std::string assignment with
  2022-02-01 21:24 [Bug tree-optimization/104336] New: bogus -Wrestrict for std::string assignment with msebor at gcc dot gnu.org
  2022-02-01 21:25 ` [Bug tree-optimization/104336] " msebor at gcc dot gnu.org
  2022-04-25 19:11 ` mattias.ellert at physics dot uu.se
@ 2022-04-25 20:26 ` amacleod at redhat dot com
  2022-05-02 12:45 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: amacleod at redhat dot com @ 2022-04-25 20:26 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Macleod <amacleod at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amacleod at redhat dot com

--- Comment #2 from Andrew Macleod <amacleod at redhat dot com> ---
Huh.  This looks earily familiar to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329 as well.

That PR documents why the code sequence isn't handled well by the optimizers in
this release...  we improve analysis on the length calculation, but not on the
pointer side... so we leave dead code that the warning system complains about.  

Presumably this would also fix that?

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

* [Bug tree-optimization/104336] bogus -Wrestrict for std::string assignment with
  2022-02-01 21:24 [Bug tree-optimization/104336] New: bogus -Wrestrict for std::string assignment with msebor at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-04-25 20:26 ` amacleod at redhat dot com
@ 2022-05-02 12:45 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-02 12:45 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
let's mark this one as duplicate

*** This bug has been marked as a duplicate of bug 105329 ***

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

end of thread, other threads:[~2022-05-02 12:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-01 21:24 [Bug tree-optimization/104336] New: bogus -Wrestrict for std::string assignment with msebor at gcc dot gnu.org
2022-02-01 21:25 ` [Bug tree-optimization/104336] " msebor at gcc dot gnu.org
2022-04-25 19:11 ` mattias.ellert at physics dot uu.se
2022-04-25 20:26 ` amacleod at redhat dot com
2022-05-02 12:45 ` rguenth 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).