From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 55C51384D363; Mon, 11 Apr 2022 12:38:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55C51384D363 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/100370] [11/12 Regression] Incorrect -Wplacement-new with union Date: Mon, 11 Apr 2022 12:38:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.1.0 X-Bugzilla-Keywords: diagnostic, patch X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: jason at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Apr 2022 12:38:34 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100370 --- Comment #4 from CVS Commits --- The master branch has been updated by Jason Merrill : https://gcc.gnu.org/g:790b02af6a1fcfa07dba6129909b3578a55a51fa commit r12-8079-g790b02af6a1fcfa07dba6129909b3578a55a51fa Author: Jason Merrill Date: Tue Apr 5 22:29:06 2022 -0400 c++: -Wplacement-new and anon union member [PR100370] This bug was an object/value confusion; we are interested in the size of *b.ip, but instead the code was calculating the size of b.ip itself. This seems to be because compute_objsize will compute the size of whate= ver object it can find in the argument: if you pass it a VAR_DECL, it gives= you the size of that variable. If you pass it an ADDR_EXPR of a VAR_DECL, = it again gives you the size of the variable. The way you can tell the difference is by looking at the deref member of access_ref: if it's -1,= the argument is a pointer to the object. Since that's what we're interested in, we should check for that, like check_dangling_stores does. This regressed some tests because compute_objsize_r was wrongly zeroing deref in the POINTER_PLUS_EXPR handling; adding an offset to a pointer doesn't change whether the pointer is itself a variable or a pointer to one. In fact, handling POINTER_PLUS_EXPR only really makes sense for d= eref =3D=3D -1, where we're adjusting a pointer to the variable. PR c++/100370 gcc/cp/ChangeLog: * init.cc (warn_placement_new_too_small): Check deref. gcc/ChangeLog: * pointer-query.cc (compute_objsize_r) [POINTER_PLUS_EXPR]: Req= uire deref =3D=3D -1. gcc/testsuite/ChangeLog: * g++.dg/warn/Wplacement-new-size-11.C: New test.=