r218378 - Sema: Inherit the flexible array property from struct fields

David Majnemer david.majnemer at gmail.com
Wed Sep 24 15:33:10 PDT 2014


On Wed, Sep 24, 2014 at 3:27 PM, Robinson, Paul <
Paul_Robinson at playstation.sony.com> wrote:

> > -----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."
>

This fixes a different bug, we were crashing elsewhere in Sema when
checking the implicit constructor because we saw an incomplete array type
in an unexpected case.

PR21040 is a different matter, we need to consider a constant array with a
bound of zero to be a flexible array member.


> Thanks,
> --paulr
>
> >
> >  struct inotify_event
> >  {
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140924/be4ca50d/attachment.html>


More information about the cfe-commits mailing list