From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3CBA13858D33; Tue, 14 Mar 2023 18:56:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CBA13858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678820165; bh=R/Yt7hELUdGgby75thSaEsU4Pgc5XWvDsZIPDvMSc+M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bU2HedA4BL0e6oY7WDt+JpRyb9L/bqVYK1BovVuk2sPzggP2r095UHeblcQFYW5zT tVrn/r2MDEQF7cBmmqd1AGdXp4zJ8LOx3eNiqpvn9eAcNBqokqkOylTwiBI4o/byQj 90hYB9JIJl3qBZ6um3w5V0MUg6qOOgY4naIJtjlc= From: "romain.geissler at amadeus dot com" 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: Tue, 14 Mar 2023 18:56:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: romain.geissler at amadeus dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106238 --- Comment #6 from Romain Geissler --- Hi, After upgrading to the latest gcc trunk, I have hit another variant of this problem. For people just willing to exchange containers with swap, just swapping the arguments makes it work, and actually has the same logic: #include void f(std::set& a) { std::set b; // b.swap(a); // Ok and has same effect a.swap(b); // KO } Compiled on x86_64 with -O2 -Werror=3Ddangling-pointer: In file included from /opt/compiler-explorer/gcc-trunk-20230314/include/c++/13.0.1/set:62, from :1: In member function 'void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::swap(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&) [w= ith _Key =3D int; _Val =3D int; _KeyOfValue =3D std::_Identity; _Compare = =3D std::less; _Alloc =3D std::allocator]', inlined from 'void std::set<_Key, _Compare, _Alloc>::swap(std::set<_Key, _Compare, _Alloc>&) [with _Key =3D int; _Compare =3D std::less; _Alloc= =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20230314/include/c++/13.0.1/bits/stl_set.h= :443:18, inlined from 'void f(std::set&)' at :8:11: /opt/compiler-explorer/gcc-trunk-20230314/include/c++/13.0.1/bits/stl_tree.= h:2092:36: error: storing the address of local variable 'b' in '*MEM[(struct _Rb_tree_node_base * &)&b + 16].std::_Rb_tree_node_base::_M_parent' [-Werror=3Ddangling-pointer=3D] 2092 | __t._M_root()->_M_parent =3D __t._M_end(); | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~ : In function 'void f(std::set&)': :5:19: note: 'b' declared here 5 | std::set b; | ^ :5:19: note: 'b.std::set, std::allocator >::_M_t.std::_Rb_tree, std::less, std::allocator >::_M_impl.std::_Rb_tree, std::less, std::allocator >::_Rb_tree_impl, true>::.std::_Rb_tree_header::_M_header.std::_Rb_tree_node_base::_= M_parent' declared here cc1plus: some warnings being treated as errors Compiler returned: 1=