From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18151 invoked by alias); 13 Jan 2014 11:43:48 -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 18102 invoked by uid 48); 13 Jan 2014 11:43:45 -0000 From: "amodra at gmail dot com" 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:43: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: amodra at gmail dot com 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: 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/msg01344.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28865 --- Comment #19 from Alan Modra --- 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. The testcase (which is invalid code IMO) in comment #3 hits this assert in varasm.c: /* Advance to offset of this element. Note no alignment needed in an array, since that is guaranteed if each element has the proper size. */ if ((local->field != NULL_TREE || local->index != NULL_TREE) && fieldpos != local->total_bytes) { gcc_assert (fieldpos >= local->total_bytes);