From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AA9DA3850874; Tue, 28 Mar 2023 23:35:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AA9DA3850874 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680046512; bh=DO0zj51m4y11po5303fgbcW/tkS4QCJhnUk25O6zrRo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PKli6NoZdWndiVCjU551DvZjPFv9dZvgwSzF6lCFC/W8P3/pEQuu6pkOd854IZ2ua TT0OTv3vz1NzkXwxKx32rBua/KXFEKJgYZXwRyw6Musuxt2ujC3uNfD4gMv2SxjULb xHX/sA8aut/FyAG6u8r2o3GoahxhMwsoEFjixn2w= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/108554] [12 Regression] Warning "null pointer dereferece" raised when extracting a unique_ptr from a map and any "-O" flag Date: Tue, 28 Mar 2023 23:35:11 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 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=3D108554 --- Comment #8 from CVS Commits --- The releases/gcc-12 branch has been updated by Jonathan Wakely : https://gcc.gnu.org/g:2fdfa3768b25c85df39eaf9b850e130e42a4dd6f commit r12-9345-g2fdfa3768b25c85df39eaf9b850e130e42a4dd6f Author: Jonathan Wakely Date: Thu Jan 26 10:55:28 2023 +0000 libstdc++: Add returns_nonnull to non-inline std::map detail [PR108554] std::map uses a non-inline function to rebalance its tree and the compiler can't see that it always returns a valid pointer (assuming valid inputs, which is a precondition anyway). This can result in -Wnull-derefernce warnings for valid code, because the compiler thinks there is a path where the function returns null. Adding the returns_nonnull attribute tells the compiler that is can't happen. While we're doing that, we might as well also add a nonnull attribute to the rebalancing functions too. libstdc++-v3/ChangeLog: PR libstdc++/108554 * include/bits/stl_tree.h (_Rb_tree_insert_and_rebalance): Add nonnull attribute. (_Rb_tree_rebalance_for_erase): Add nonnull and returns_nonnull attributes. * testsuite/23_containers/map/modifiers/108554.cc: New test. (cherry picked from commit 3376467ce090aa0966d59ca3aea35db4f17a4b47)=