From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22322 invoked by alias); 13 Jan 2014 11:52:45 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 22258 invoked by uid 48); 13 Jan 2014 11:52:42 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/28865] Structures with a flexible arrray member have wrong .size Date: Mon, 13 Jan 2014 11:52:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.2.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.7.4 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-01/txt/msg01345.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28865 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jsm28 at gcc dot gnu.org --- Comment #20 from Jakub Jelinek --- (In reply to Alan Modra from comment #19) > Jakub, you're correct. I should have read the standard on flexible array > members before poking at this bug last year. Nick's patch is looking good > to me. > > ISO/IEC 9899:1999 is quite clear that the answer to comment #2 is that > sizeof does *not* include the flexible array component (but it does include > any padding needed to align the start of the flexible array). I think it is > reasonable to do the same for .size and not include the flexible array > component there too. Well, sizeof is clear, but .size doesn't need to be the same thing, IMHO .size really should be DECL_SIZE of the decl and we do adjust that for the flexible array member in there. If .size would be just e.g. TYPE_SIZE, then there could be e.g. problems with copy relocations. > > The testcase (which is invalid code IMO) in comment #3 hits this assert in > varasm.c: The #c3 is invalid, I agree, how can you have an array if each array entry has a different size? I mean, the C standard allows flexible array members only at the toplevel and not initialized, as GNU extension we allow it to be initialized and allow it even in some cases where it is not toplevel, but where it is still reasonable (e.g. the case where it is at the end of struct which is inside a union is reasonable, so would be placing it at the end of another structure, but placing it in an array is IMHO something that should be rejected by the FE). CCing Joseph on it.