This is an archive of the discontinued LLVM Phabricator instance.

Sema: Treat zero sized arrays as flexible array members
Needs ReviewPublic

Authored by majnemer on Sep 24 2014, 4:22 AM.

Details

Summary

Zero sized arrays are more or less the pre-standard version of flexible
array members. It makes sense to mark structs which contain them as
hasFlexibleArrayMember.

Doing this has the side effect of resolving PR21040, a crash involving
one record inheriting from a base which is terminated with a zero sized
array field.

Diff Detail

Event Timeline

majnemer updated this revision to Diff 14028.Sep 24 2014, 4:22 AM
majnemer retitled this revision from to Sema: Treat zero sized arrays as flexible array members.
majnemer updated this object.
majnemer added reviewers: rsmith, rnk, andreadb.
majnemer added a subscriber: Unknown Object (MLST).
andreadb edited edge metadata.Sep 24 2014, 5:04 AM

Thanks for this patch.

I am not knowledgeable enough in this area to give a LGTM, but personally I like this approach.
I always thought that GCC was too permissive in general when it came to using zero-length arrays.
I agree that we should allow declaring a zero-length array as the sole element of a structure. I am not sure if it makes sense to have a zero-length array in a union.

-Andrea

rsmith edited edge metadata.Sep 29 2014, 12:21 PM

Generally, I think this is a good direction, but seems large enough to deserve a release notes change. Have you tested this against much existing code?

test/SemaCXX/zero-length-arrays.cpp
13

Can we find out what rdar://problem/10228639 was?

I haven't tested it much beyond self hosting and targeted test cases.

test/SemaCXX/zero-length-arrays.cpp
13

interaction between having a trailing zero-sized array in a struct (C++ extension) and whether that implies having a default constructor.
the usual sort of thing. language extension interaction w/ actual language standard. things get odd.

It'd be useful to figure out where we differ from the GCC documentation with this patch applied:

https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

test/SemaCXX/zero-length-arrays.cpp
13

Sounds like there was no expectation that we actually accept this then?

kcc added a subscriber: kcc.Oct 27 2014, 11:37 AM

Richard, ping?