public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "romain.geissler at amadeus dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/106238] Inline optimization causes dangling pointer on "include/c++/12.1.0/bits/stl_tree.h"
Date: Sun, 08 Jan 2023 15:45:04 +0000	[thread overview]
Message-ID: <bug-106238-4-KQ7hBAZXTT@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-106238-4@http.gcc.gnu.org/bugzilla/>

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

Romain Geissler <romain.geissler at amadeus dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |romain.geissler at amadeus dot com

--- Comment #5 from Romain Geissler <romain.geissler at amadeus dot com> ---
Hi,

This seems to still happen with current trunk:


#include <map>

std::map<int, int> _Map;

void f()
{
    std::map<int, int> localMap;
    _Map.swap(localMap);
}

compiled with -Wall -Werror -O2:

In file included from
/opt/compiler-explorer/gcc-trunk-20230108/include/c++/13.0.0/map:62,
                 from <source>:1:
In member function 'void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare,
_Alloc>::swap(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&) [with
_Key = int; _Val = std::pair<const int, int>; _KeyOfValue =
std::_Select1st<std::pair<const int, int> >; _Compare = std::less<int>; _Alloc
= std::allocator<std::pair<const int, int> >]',
    inlined from 'void std::map<_Key, _Tp, _Compare,
_Alloc>::swap(std::map<_Key, _Tp, _Compare, _Alloc>&) [with _Key = int; _Tp =
int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int,
int> >]' at
/opt/compiler-explorer/gcc-trunk-20230108/include/c++/13.0.0/bits/stl_map.h:1172:18,
    inlined from 'void f()' at <source>:8:14:
/opt/compiler-explorer/gcc-trunk-20230108/include/c++/13.0.0/bits/stl_tree.h:2091:36:
error: storing the address of local variable 'localMap' in '*MEM[(struct
_Rb_tree_node_base * &)&localMap + 16].std::_Rb_tree_node_base::_M_parent'
[-Werror=dangling-pointer=]
 2091 |           __t._M_root()->_M_parent = __t._M_end();
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
<source>: In function 'void f()':
<source>:7:24: note: 'localMap' declared here
    7 |     std::map<int, int> localMap;
      |                        ^~~~~~~~
<source>:7:24: note: 'localMap.std::map<int, int, std::less<int>,
std::allocator<std::pair<const int, int> > >::_M_t.std::_Rb_tree<int,
std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >,
std::less<int>, std::allocator<std::pair<const int, int> >
>::_M_impl.std::_Rb_tree<int, std::pair<const int, int>,
std::_Select1st<std::pair<const int, int> >, std::less<int>,
std::allocator<std::pair<const int, int> > >::_Rb_tree_impl<std::less<int>,
true>::<unnamed>.std::_Rb_tree_header::_M_header.std::_Rb_tree_node_base::_M_parent'
declared here
cc1plus: all warnings being treated as errors
Compiler returned: 1


Cheers,
Romain

  parent reply	other threads:[~2023-01-08 15:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-08 21:32 [Bug libstdc++/106238] New: " rogerio.souza at gmail dot com
2022-07-08 21:45 ` [Bug tree-optimization/106238] " pinskia at gcc dot gnu.org
2022-07-11 16:23 ` rogerio.souza at gmail dot com
2022-07-11 17:16 ` rogerio.souza at gmail dot com
2022-07-11 17:26 ` rogerio.souza at gmail dot com
2023-01-08 15:45 ` romain.geissler at amadeus dot com [this message]
2023-03-14 18:56 ` romain.geissler at amadeus dot com
2023-03-14 20:46 ` romain.geissler at amadeus dot com
2023-03-14 22:34 ` [Bug tree-optimization/106238] [12/13 regression] Inline optimization causes dangling pointer warning " jason at gcc dot gnu.org
2023-05-08 12:25 ` [Bug tree-optimization/106238] [12/13/14 " rguenth at gcc dot gnu.org
2023-08-15 22:58 ` romain.geissler at amadeus dot com
2024-03-15  1:19 ` [Bug tree-optimization/106238] [12 " law 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-106238-4-KQ7hBAZXTT@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).