r190912 - Fix ObjC @encode for C++ classes w/virtual bases.

Eli Friedman eli.friedman at gmail.com
Wed Sep 18 13:52:57 PDT 2013


On Tue, Sep 17, 2013 at 8:08 PM, jahanian <fjahanian at apple.com> wrote:

> Can you elaborate what got fixed. Are we matching gcc's behavior? I see
> that it is
> currently ""{E=^^?i^^?ii^^?}" for this test case.
>

The patch fixes an assertion failure, and also nonsensical output when
assertions are turned off.  (The encoding is supposed to match the layout
of the class, and the class has two vptrs, not three.)

-Eli


>
> - Fariborz
>
>
> On Sep 17, 2013, at 6:59 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
>
> > Author: efriedma
> > Date: Tue Sep 17 20:59:16 2013
> > New Revision: 190912
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=190912&view=rev
> > Log:
> > Fix ObjC @encode for C++ classes w/virtual bases.
> >
> > PR17142.
> >
> > Modified:
> >    cfe/trunk/lib/AST/ASTContext.cpp
> >    cfe/trunk/test/CodeGenObjCXX/encode.mm
> >
> > Modified: cfe/trunk/lib/AST/ASTContext.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=190912&r1=190911&r2=190912&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/AST/ASTContext.cpp (original)
> > +++ cfe/trunk/lib/AST/ASTContext.cpp Tue Sep 17 20:59:16 2013
> > @@ -5552,7 +5552,8 @@ void ASTContext::getObjCEncodingForStruc
> >       if (base->isEmpty())
> >         continue;
> >       uint64_t offs = toBits(layout.getVBaseClassOffset(base));
> > -      if (FieldOrBaseOffsets.find(offs) == FieldOrBaseOffsets.end())
> > +      if (offs >= uint64_t(toBits(layout.getNonVirtualSize())) &&
> > +          FieldOrBaseOffsets.find(offs) == FieldOrBaseOffsets.end())
> >         FieldOrBaseOffsets.insert(FieldOrBaseOffsets.end(),
> >                                   std::make_pair(offs, base));
> >     }
> >
> > Modified: cfe/trunk/test/CodeGenObjCXX/encode.mm
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/encode.mm?rev=190912&r1=190911&r2=190912&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/test/CodeGenObjCXX/encode.mm (original)
> > +++ cfe/trunk/test/CodeGenObjCXX/encode.mm Tue Sep 17 20:59:16 2013
> > @@ -214,3 +214,13 @@ public:
> > }
> > @end
> > // CHECK: internal global [41 x i8]
> c"{dynamic_class=\22_vptr$dynamic_class\22^^?}\00"
> > +
> > +namespace PR17142 {
> > +  struct A { virtual ~A(); };
> > +  struct B : virtual A { int y; };
> > +  struct C { virtual ~C(); int z; };
> > +  struct D : C, B { int a; };
> > +  struct E : D {};
> > +  // CHECK: @_ZN7PR171421xE = constant [14 x i8] c"{E=^^?i^^?ii}\00"
> > +  extern const char x[] = @encode(E);
> > +}
> >
> >
> > _______________________________________________
> > 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/20130918/dbfadbab/attachment.html>


More information about the cfe-commits mailing list