From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D1FBB3856260; Wed, 11 May 2022 06:22:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1FBB3856260 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/102295] ELF symbol sizes for variable-length objects are too small (C++) Date: Wed, 11 May 2022 06:22:27 +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: 12.0 X-Bugzilla-Keywords: wrong-code 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: jakub 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 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: Wed, 11 May 2022 06:22:27 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102295 --- Comment #14 from CVS Commits --- The releases/gcc-9 branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:bd1562be917d088f8a34a27c4f91091382cbd4ab commit r9-10101-gbd1562be917d088f8a34a27c4f91091382cbd4ab Author: Jakub Jelinek Date: Wed Sep 15 22:21:17 2021 +0200 c++: Fix handling of decls with flexible array members initialized with side-effects [PR88578] > > Note, if the flexible array member is initialized only with non-constant > > initializers, we have a worse bug that this patch doesn't solve, the > > splitting of initializers into constant and dynamic initialization removes > > the initializer and we don't have just wrong DECL_*SIZE, but nothin= g is > > emitted when emitting those vars into assembly either and so the dynamic > > initialization clobbers other vars that may overlap the variable. > > I think we need keep an empty CONSTRUCTOR elt in DECL_INITIAL for t= he > > flexible array member in that case. > > Makes sense. So, the following patch fixes that. The typeck2.c change makes sure we keep those CONSTRUCTORs around (alth= ough they should be empty because all their elts had side-effects/was non-constant if it was removed earlier), and the varasm.c change is to avoid ICEs on those as well as ICEs on other flex array members that had some initializers without side-effects, but not on the last array element. The code was already asserting that the (index of the last elt in the CONSTRUCTOR + 1) times elt size is equal to TYPE_SIZE_UNIT of the local->val type, which is true for C flex arrays or for C++ if they don't have any side-effects or the last elt doesn't have side-effects, this patch chan= ges that to assertion that the TYPE_SIZE_UNIT is greater than equal to the offset of the end of last element in the CONSTRUCTOR and uses TYPE_SIZE_UNIT (int_size_in_bytes) in the code later on. 2021-09-15 Jakub Jelinek PR c++/88578 PR c++/102295 gcc/ * varasm.c (output_constructor_regular_field): Instead of asser= tion that array_size_for_constructor result is equal to size of TREE_TYPE (local->val) in bytes, assert that the type size is greater or equal to array_size_for_constructor result and use type size= as fieldsize. gcc/cp/ * typeck2.c (split_nonconstant_init_1): Don't throw away empty initializers of flexible array members if they have non-zero ty= pe size. gcc/testsuite/ * g++.dg/ext/flexary39.C: New test. * g++.dg/ext/flexary40.C: New test. (cherry picked from commit e5d1af8a07ae9fcc40ea5c781c3ad46d20ea12a6)=