public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/106238] New: Inline optimization causes dangling pointer on "include/c++/12.1.0/bits/stl_tree.h"
@ 2022-07-08 21:32 rogerio.souza at gmail dot com
  2022-07-08 21:45 ` [Bug tree-optimization/106238] " pinskia at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: rogerio.souza at gmail dot com @ 2022-07-08 21:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106238
           Summary: Inline optimization causes dangling pointer on
                    "include/c++/12.1.0/bits/stl_tree.h"
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rogerio.souza at gmail dot com
  Target Milestone: ---

Created attachment 53282
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53282&action=edit
Preprocessed file to reroduce the issue

When compiling the code below, we get a dangling pointer warning.

====================================================================
#include <map>

struct sysDLoc {                        /* Coordinates (in DBU) */
  double        x, y;
};

std::map<int*, sysDLoc> static_copy;

void realSwap()
{
  std::map<int*, sysDLoc> local_copy;
  extern void getLocalCopy(std::map<int*, sysDLoc>&);
  getLocalCopy(local_copy);
  local_copy.swap(static_copy);
}
====================================================================

Compilation command:
g++ -Wdangling-pointer -c -O2 bug.cpp


Warning log:
In file included from
/grid/common/test/gcc-v12.1.0d2rh74_lnx86/include/c++/12.1.0/map:60,
                 from bug.cpp: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<int* const, sysDLoc>; _KeyOfValue =
std::_Select1st<std::pair<int* const, sysDLoc> >; _Compare = std::less<int*>;
_Alloc = std::allocator<std::pair<int* const, sysDLoc> >]',
    inlined from 'void std::map<_Key, _Tp, _Compare,
_Alloc>::swap(std::map<_Key, _Tp, _Compare, _Alloc>&) [with _Key = int*; _Tp =
sysDLoc; _Compare = std::less<int*>; _Alloc = std::allocator<std::pair<int*
const, sysDLoc> >]' at
/grid/common/test/gcc-v12.1.0d2rh74_lnx86/include/c++/12.1.0/bits/stl_map.h:1172:18,
    inlined from 'void realSwap()' at bug.cpp:14:18:
/grid/common/test/gcc-v12.1.0d2rh74_lnx86/include/c++/12.1.0/bits/stl_tree.h:2090:32:
warning: storing the address of local variable 'local_copy' in '*MEM[(struct
_Rb_tree_node_base * &)&local_copy + 16].std::_Rb_tree_node_base::_M_paren
' [-Wdangling-pointer=]
 2090 |           _M_root()->_M_parent = _M_end();
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
bug.cpp: In function 'void realSwap()':
bug.cpp:11:27: note: 'local_copy' declared here
   11 |   std::map<int*, sysDLoc> local_copy;
      |                           ^~~~~~~~~~
bug.cpp:11:27: note: 'local_copy.std::map<int*, sysDLoc, std::less<int*>,
std::allocator<std::pair<int* const, sysDLoc> > >::_M_t.std::_Rb_tree<int*,
std::pair<int* const, sysDLoc>, std::_Select1st<std::pair<int* const, sysDLoc>
>, std::less<int*>, std::allocator<std::pair<int* const, sysDLoc> >
>::_M_impl.std::_Rb_tree<int*, std::pair<int* const, sysDLoc>,
std::_Select1st<std::pair<int* const, sysDLoc> >, std::less<int*>,
std::allocator<std::pair<int* const, sysDLoc> >
>::_Rb_tree_impl<std::less<int*>,
true>::<unnamed>.std::_Rb_tree_header::_M_header.std::_Rb_tree_node_base::_M_parent'
declared here

This warning only happens on GCC v12.1. Using -O1,
"-fno-inline-small-functions”, or  “-fno-inline-functions” prevents the error
from happening.

Regards,
Rogerio

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

end of thread, other threads:[~2024-03-15  1:19 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-08 21:32 [Bug libstdc++/106238] New: Inline optimization causes dangling pointer on "include/c++/12.1.0/bits/stl_tree.h" 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
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

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).