This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/28865] Structures with a flexible arrray member have wrong .size


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28865

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jsm28 at gcc dot gnu.org

--- Comment #20 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]