r218378 - Sema: Inherit the flexible array property from struct fields
Robinson, Paul
Paul_Robinson at playstation.sony.com
Wed Sep 24 15:27:23 PDT 2014
> -----Original Message-----
> From: cfe-commits-bounces at cs.uiuc.edu [mailto:cfe-commits-
> bounces at cs.uiuc.edu] On Behalf Of David Majnemer
> Sent: Wednesday, September 24, 2014 4:04 AM
> To: cfe-commits at cs.uiuc.edu
> Subject: r218378 - Sema: Inherit the flexible array property from struct
> fields
>
> Author: majnemer
> Date: Wed Sep 24 06:04:09 2014
> New Revision: 218378
>
> URL: http://llvm.org/viewvc/llvm-project?rev=218378&view=rev
> Log:
> Sema: Inherit the flexible array property from struct fields
>
> A record which contains a flexible array member is itself a flexible
> array member. A struct which contains such a record should also
> consider itself to be a flexible array member.
>
> Modified:
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/SemaCXX/flexible-array-test.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=218378&r1=218377&r2=218378&vie
> w=diff
> ==========================================================================
> ====
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Sep 24 06:04:09 2014
> @@ -12704,8 +12704,7 @@ void Sema::ActOnFields(Scope *S, SourceL
> continue;
> }
> // Okay, we have a legal flexible array member at the end of the
> struct.
> - if (Record)
> - Record->setHasFlexibleArrayMember(true);
> + Record->setHasFlexibleArrayMember(true);
> } else if (!FDTy->isDependentType() &&
> RequireCompleteType(FD->getLocation(), FD->getType(),
> diag::err_field_incomplete)) {
> @@ -12714,11 +12713,11 @@ void Sema::ActOnFields(Scope *S, SourceL
> EnclosingDecl->setInvalidDecl();
> continue;
> } else if (const RecordType *FDTTy = FDTy->getAs<RecordType>()) {
> - if (FDTTy->getDecl()->hasFlexibleArrayMember()) {
> - // If this is a member of a union, then entire union becomes
> "flexible".
> - if (Record && Record->isUnion()) {
> - Record->setHasFlexibleArrayMember(true);
> - } else {
> + if (Record && FDTTy->getDecl()->hasFlexibleArrayMember()) {
> + // A type which contains a flexible array member is considered to
> be a
> + // flexible array member.
> + Record->setHasFlexibleArrayMember(true);
> + if (!Record->isUnion()) {
> // If this is a struct/class and this is not the last element,
> reject
> // it. Note that GCC supports variable sized arrays in the
> middle of
> // structures.
> @@ -12730,8 +12729,6 @@ void Sema::ActOnFields(Scope *S, SourceL
> // other structs as an extension.
> Diag(FD->getLocation(), diag::ext_flexible_array_in_struct)
> << FD->getDeclName();
> - if (Record)
> - Record->setHasFlexibleArrayMember(true);
> }
> }
> }
>
> Modified: cfe/trunk/test/SemaCXX/flexible-array-test.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/flexible-
> array-test.cpp?rev=218378&r1=218377&r2=218378&view=diff
> ==========================================================================
> ====
> --- cfe/trunk/test/SemaCXX/flexible-array-test.cpp (original)
> +++ cfe/trunk/test/SemaCXX/flexible-array-test.cpp Wed Sep 24 06:04:09
> 2014
> @@ -14,6 +14,12 @@ void QMap<Key, T>::insert(const Key &, c
> v = avalue;
> }
>
> +struct Rec {
> + union { // expected-warning-re {{variable sized type '{{.*}}' not at
> the end of a struct or class is a GNU extension}}
> + int u0[];
> + };
> + int x;
> +} rec;
If this is for PR21040, maybe there should be another test for array[0]?
(Also would be nice to mention the PR in the commit log...)
But if this isn't the complete fix for 21040... "never mind."
Thanks,
--paulr
>
> struct inotify_event
> {
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list