From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 61ACD3858C27; Mon, 16 Nov 2020 17:10:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61ACD3858C27 From: "jason at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/97595] [11 Regression] bogus -Wstringop-overflow due to DECL_SIZE_UNIT underreporting field size Date: Mon, 16 Nov 2020 17:10:03 +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: 11.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: jason at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.0 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, 16 Nov 2020 17:10:03 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97595 --- Comment #5 from Jason Merrill --- (In reply to Martin Sebor from comment #3) > I can confirm the warning but I'm not sure the bug is in the middle end > code. Let me CC Jason for his comments. >=20 > The warning triggers for the MEM_REF below: >=20 > MEM[(char &)_10 + 224] =3D _24; >=20 > in the following GIMPLE ("type" is char). The destination of the access = is > this_3(D)->D.45669 which is the basic_istream subobject. Its size report= ed > by DECL_SIZE_UNIT() in component_ref_size() is 16. The initial offset > (i.e., _10) is indeterminate but it's taken to be in the range bounded by > the size of the object, or [0, 16]. Given that, the constant offset 224 = is > determined to be out of bounds. What you're seeing is that the DECL_SIZE of the base subobject excludes any virtual bases, because they are laid out in the most derived class, while t= he TYPE_SIZE of the base type includes them. CLASSTYPE_SIZE of the base type should match the DECL_SIZE. It's definitely OK for a program to refer to a virtual base through any of = the derived classes. > The change introduced in r11-3827 that triggers the warning is the assump= tion > that unless determined otherwise, an indeterminate offset into an ob= ject must > be bounded by the object's size. So this assumption is invalid for base subobjects of types with virtual bas= es; such an offset is only bounded by the most-derived object's size.=