public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "spriteovo at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/110055] New: Dangling pointer warning inside std::vector on RISC-V
Date: Wed, 31 May 2023 10:03:43 +0000	[thread overview]
Message-ID: <bug-110055-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110055
           Summary: Dangling pointer warning inside std::vector on RISC-V
           Product: gcc
           Version: 13.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: spriteovo at gmail dot com
  Target Milestone: ---

This bug can only be reproduce on RISC-V platform.

Minimum reproducible example:

```cpp
#include <cstdint>
#include <vector>

struct Data {
  std::vector<uint16_t> v = {1, 1};
};

int main() {
  Data a;
  Data b;
}
```

Compile with `g++ main.cpp -Werror -Wall -fno-exceptions -O3`

Error message:

```
In file included from /usr/include/c++/13.1.1/vector:62,
                 from main.cpp:2:
In static member function ‘static _Up* std::__copy_move<_IsMove, true,
std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = const
short unsigned int; _Up = short unsigned int; bool _IsMove = false]’,
    inlined from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove =
false; _II = const short unsigned int*; _OI = short unsigned int*]’ at
/usr/include/c++/13.1.1/bits/stl_algobase.h:506:30,
    inlined from ‘_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove =
false; _II = const short unsigned int*; _OI = short unsigned int*]’ at
/usr/include/c++/13.1.1/bits/stl_algobase.h:533:42,
    inlined from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove =
false; _II = const short unsigned int*; _OI = short unsigned int*]’ at
/usr/include/c++/13.1.1/bits/stl_algobase.h:540:31,
    inlined from ‘_OI std::copy(_II, _II, _OI) [with _II = const short unsigned
int*; _OI = short unsigned int*]’ at
/usr/include/c++/13.1.1/bits/stl_algobase.h:633:7,
    inlined from ‘static _ForwardIterator
std::__uninitialized_copy<true>::__uninit_copy(_InputIterator, _InputIterator,
_ForwardIterator) [with _InputIterator = const short unsigned int*;
_ForwardIterator = short unsigned int*]’ at
/usr/include/c++/13.1.1/bits/stl_uninitialized.h:147:27,
    inlined from ‘_ForwardIterator std::uninitialized_copy(_InputIterator,
_InputIterator, _ForwardIterator) [with _InputIterator = const short unsigned
int*; _ForwardIterator = short unsigned int*]’ at
/usr/include/c++/13.1.1/bits/stl_uninitialized.h:185:15,
    inlined from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator,
_InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator = const
short unsigned int*; _ForwardIterator = short unsigned int*; _Tp = short
unsigned int]’ at /usr/include/c++/13.1.1/bits/stl_uninitialized.h:373:37,
    inlined from ‘void std::vector<_Tp,
_Alloc>::_M_range_initialize(_ForwardIterator, _ForwardIterator,
std::forward_iterator_tag) [with _ForwardIterator = const short unsigned int*;
_Tp = short unsigned int; _Alloc = std::allocator<short unsigned int>]’ at
/usr/include/c++/13.1.1/bits/stl_vector.h:1692:33,
    inlined from ‘std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>,
const allocator_type&) [with _Tp = short unsigned int; _Alloc =
std::allocator<short unsigned int>]’ at
/usr/include/c++/13.1.1/bits/stl_vector.h:679:21,
    inlined from ‘constexpr Data::Data()’ at main.cpp:4:8,
    inlined from ‘int main()’ at main.cpp:10:8:
/usr/include/c++/13.1.1/bits/stl_algobase.h:437:30: error: using a dangling
pointer to ‘C.0’ [-Werror=dangling-pointer=]
  437 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:4:8: note: ‘C.0’ declared here
    4 | struct Data {
      |        ^~~~
cc1plus: all warnings being treated as errors
```

             reply	other threads:[~2023-05-31 10:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31 10:03 spriteovo at gmail dot com [this message]
2023-05-31 10:05 ` [Bug c++/110055] " spriteovo at gmail dot com
2023-05-31 13:32 ` spriteovo at gmail dot com
2023-05-31 23:46 ` [Bug middle-end/110055] " pinskia at gcc dot gnu.org
2023-05-31 23:47 ` pinskia at gcc dot gnu.org
2023-06-01  0:07 ` pinskia at gcc dot gnu.org
2023-06-02  7:13 ` rguenth at gcc dot gnu.org
2023-06-02  7:25 ` rguenth at gcc dot gnu.org
2023-06-05 11:15 ` spriteovo at gmail dot com
2023-06-06  8:30 ` cvs-commit at gcc dot gnu.org
2023-06-06  8:41 ` [Bug middle-end/110055] [13 Regression] " rguenth at gcc dot gnu.org
2023-06-23 10:30 ` cvs-commit at gcc dot gnu.org
2023-06-23 10:30 ` rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110055-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).