Hi gcc-patches mailing list,
dkm via Sourceware Forge <[email protected]> has 
requested that the following forgejo pull request
be published on the mailing list.

Created on: 2026-05-28 20:29:27+00:00
Latest update: 2026-05-29 11:39:51+00:00
Changes: 1 changed files, 21 additions, 2 deletions
Head revision: dkm/gcc-TEST ref dkm/gccrs_fix commit 
07b3e7e9cf2bc1db119920100f1155055d3e5571
Base revision: gcc/gcc-TEST ref trunk commit 
2fa2088a13bbfb37b900a623507bf2b4c15c1f1b r17-968-g2fa2088a13bbfb
Merge base: 2fa2088a13bbfb37b900a623507bf2b4c15c1f1b
Full diff url: https://forge.sourceware.org/gcc/gcc-TEST/pulls/162.diff
Discussion:  https://forge.sourceware.org/gcc/gcc-TEST/pulls/162
Requested Reviewers: cohenarthur

Recent change gives:

```
In file included from 
/gccrs/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/string:45,
                 from ../../gcc/rust/rust-system.h:34,
                 from ../../gcc/rust/lex/rust-token.cc:19:
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 
/gccrs/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:4
87:21,
    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 
/gccrs/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:4
82:7,
    inlined from 'constexpr void std::__cxx11::basic_string<_CharT, _Traits, 
_Alloc>::_M_mutate(size_type, size_type, const _CharT*, size_type) [with _CharT 
= char; _Trait
s = std::char_traits<char>; _Alloc = std::allocator<char>]' at 
/gccrs/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_st
ring.tcc:403:15,
    inlined from 'constexpr std::__cxx11::basic_string<_CharT, _Traits, 
_Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_append(const 
_CharT*, size_type) [
with _CharT = char; _Traits = std::char_traits<char>; _Alloc = 
std::allocator<char>]' at /gccrs/build/prev-x86_64-pc-linux-gnu/libstdc+
+-v3/include/bits/basic_string.tcc:498:17,
    inlined from 'constexpr std::__cxx11::basic_string<_CharT, _Traits, 
_Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(const 
_CharT*, size_type) [wit
h _CharT = char; _Traits = std::char_traits<char>; _Alloc = 
std::allocator<char>]' at /gccrs/build/prev-x86_64-pc-linux-gnu/libstdc++-v
3/include/bits/basic_string.h:1624:18,
    inlined from 'constexpr _Str std::__str_concat(const typename 
_Str::value_type*, typename _Str::size_type, const typename _Str::value_type*, 
typename _Str::size_type,
const typename _Str::allocator_type&) [with _Str = 
__cxx11::basic_string<char>]' at 
/gccrs/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/
include/bits/basic_string.h:3908:19,
    inlined from 'constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc> 
std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Alloc>&, const 
_CharT*) [with
_CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]' at 
/gccrs/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/bi
ts/basic_string.h:3984:31,
    inlined from 'std::string Rust::Token::as_string() const' at 
../../gcc/rust/lex/rust-token.cc:251:45:
/gccrs/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/bits/char_traits.h:432:56:
 error: 'void* __builtin_memcpy(void*, const void*
, long unsigned int)' accessing 18446744073709551609 or more bytes at offsets 0 
and 0 overlaps 9223372036854775795 bytes at offset -9223372036854775802 
[-Werror=restrict]
  432 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, 
__n));
      |                                        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

```
Split the concatenation to avoid the warning.

Fix comes from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125404#c2

gcc/rust/ChangeLog:
        PR tree-optimization/114385
        * lex/rust-token.cc (Token::as_string): split concatenation.

Co-authored-by: Andreas Schwab <[email protected]>


Changed files:
- M: gcc/rust/lex/rust-token.cc


Marc Poulhiès (1):
  gccrs: workaround  -Wrestrict false positive [PR114385]

 gcc/rust/lex/rust-token.cc | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

Range-diff against v1:
1:  b44e89372583 ! 1:  07b3e7e9cf2b gccrs: workaround  -Wrestrict false 
positive [PR114385]
    @@ Commit message
     
         Split the concatenation to avoid the warning.
     
    +    Fix comes from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125404#c2
    +
         gcc/rust/ChangeLog:
                 PR tree-optimization/114385
                 * lex/rust-token.cc (Token::as_string): split concatenation.
     
         Co-authored-by: Andreas Schwab <[email protected]>
    +    Signed-off-by: Marc Poulhiès <[email protected]>
     
      ## gcc/rust/lex/rust-token.cc ##
     @@ gcc/rust/lex/rust-token.cc: Token::as_string () const
    @@ gcc/rust/lex/rust-token.cc: Token::as_string () const
            return get_str ();
          else
     -      return get_str () + get_type_hint_str ();
    ++      /* FIXME: This is a workaround for an overzealous -Wrestrict,
    ++         #125404 - we should remove it once it is fixed
    ++
    ++         return get_str () + get_type_hint_str ();
    ++         */
     +      {
     +        std::string s = get_str ();
     +        s += get_type_hint_str ();
    @@ gcc/rust/lex/rust-token.cc: Token::as_string () const
          if (get_type_hint () == CORETYPE_UNKNOWN)
            return get_str ();
          else
    +-      return get_str () + get_type_hint_str ();
    ++      /* FIXME: This is a workaround for an overzealous -Wrestrict,
    ++         #125404 - we should remove it once it is fixed
    ++
    ++         return get_str () + get_type_hint_str ();
    ++         */
     +      {
     +        std::string s = get_str ();
     +        s += get_type_hint_str ();
     +        return s;
     +      }
    -       return get_str () + get_type_hint_str ();
    ++
        default:
          return get_str ();
    +   }
-- 
2.54.0

Reply via email to