[cfe-commits] r111823 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaDecl.cpp lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriterDecl.cpp test/CodeGenObjC/ivar-layout-nonfragile-abi2.m

Fariborz Jahanian fjahanian at apple.com
Mon Aug 23 11:51:39 PDT 2010


Author: fjahanian
Date: Mon Aug 23 13:51:39 2010
New Revision: 111823

URL: http://llvm.org/viewvc/llvm-project?rev=111823&view=rev
Log:
Support for IRGen of synthesize bitfield ivars in
objc-nonfragile-abi2 (radar 7824380).

Added:
    cfe/trunk/test/CodeGenObjC/ivar-layout-nonfragile-abi2.m
Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=111823&r1=111822&r2=111823&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Aug 23 13:51:39 2010
@@ -1269,6 +1269,10 @@
   /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
   /// and returns the result type of that conversion.
   QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
+  
+  void ResetObjCLayout(const ObjCContainerDecl *CD) {
+    ObjCLayouts[CD] = 0;
+  }
 
   //===--------------------------------------------------------------------===//
   //                    Integer Predicates
@@ -1409,7 +1413,7 @@
  
   const ASTRecordLayout &getObjCLayout(const ObjCInterfaceDecl *D,
                                        const ObjCImplementationDecl *Impl);
-  
+
 private:
   /// \brief A set of deallocations that should be performed when the 
   /// ASTContext is destroyed.

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=111823&r1=111822&r2=111823&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Aug 23 13:51:39 2010
@@ -919,6 +919,9 @@
   /// FIXME: this should not be a singly-linked list.  Move storage elsewhere.
   ObjCCategoryDecl *NextClassCategory;
 
+  /// true of class extension has at least one bitfield ivar.
+  bool HasSynthBitfield : 1;
+  
   /// \brief The location of the '@' in '@interface'
   SourceLocation AtLoc;
 
@@ -929,8 +932,8 @@
                    SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
                    IdentifierInfo *Id)
     : ObjCContainerDecl(ObjCCategory, DC, ClassNameLoc, Id),
-      ClassInterface(0), NextClassCategory(0), AtLoc(AtLoc), 
-      CategoryNameLoc(CategoryNameLoc) {
+      ClassInterface(0), NextClassCategory(0), HasSynthBitfield(false),
+      AtLoc(AtLoc), CategoryNameLoc(CategoryNameLoc) {
   }
 public:
 
@@ -982,6 +985,9 @@
   bool IsClassExtension() const { return getIdentifier() == 0; }
   const ObjCCategoryDecl *getNextClassExtension() const;
   
+  bool hasSynthBitfield() const { return HasSynthBitfield; }
+  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
+  
   typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
   ivar_iterator ivar_begin() const {
     return ivar_iterator(decls_begin());
@@ -1154,11 +1160,15 @@
   CXXBaseOrMemberInitializer **IvarInitializers;
   unsigned NumIvarInitializers;
   
+  /// true of class extension has at least one bitfield ivar.
+  bool HasSynthBitfield : 1;
+  
   ObjCImplementationDecl(DeclContext *DC, SourceLocation L,
                          ObjCInterfaceDecl *classInterface,
                          ObjCInterfaceDecl *superDecl)
     : ObjCImplDecl(ObjCImplementation, DC, L, classInterface),
-       SuperClass(superDecl), IvarInitializers(0), NumIvarInitializers(0) {}
+       SuperClass(superDecl), IvarInitializers(0), NumIvarInitializers(0),
+       HasSynthBitfield(false) {}
 public:
   static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
                                         SourceLocation L,
@@ -1196,6 +1206,9 @@
   void setIvarInitializers(ASTContext &C,
                            CXXBaseOrMemberInitializer ** initializers,
                            unsigned numInitializers);
+  
+  bool hasSynthBitfield() const { return HasSynthBitfield; }
+  void setHasSynthBitfield (bool val) { HasSynthBitfield = val; }
     
   /// getIdentifier - Get the identifier that names the class
   /// interface associated with this implementation.

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=111823&r1=111822&r2=111823&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Aug 23 13:51:39 2010
@@ -604,10 +604,17 @@
     // decl contexts, the previously built IvarList must be rebuilt.
     ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(DC);
     if (!ID) {
-      if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC))
+      if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC)) {
         ID = IM->getClassInterface();
-      else
-        ID = (cast<ObjCCategoryDecl>(DC))->getClassInterface();
+        if (BW)
+          IM->setHasSynthBitfield(true);
+      }
+      else {
+        ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC);
+        ID = CD->getClassInterface();
+        if (BW)
+          CD->setHasSynthBitfield(true);
+      }
     }
     ID->setIvarList(0);
   }

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=111823&r1=111822&r2=111823&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Aug 23 13:51:39 2010
@@ -1940,9 +1940,16 @@
   // Forward declarations, no (immediate) code generation.
   case Decl::ObjCClass:
   case Decl::ObjCForwardProtocol:
-  case Decl::ObjCCategory:
   case Decl::ObjCInterface:
     break;
+  
+    case Decl::ObjCCategory: {
+      ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D);
+      if (CD->IsClassExtension() && CD->hasSynthBitfield())
+        Context.ResetObjCLayout(CD->getClassInterface());
+      break;
+    }
+      
 
   case Decl::ObjCProtocol:
     Runtime->GenerateProtocol(cast<ObjCProtocolDecl>(D));
@@ -1956,6 +1963,8 @@
 
   case Decl::ObjCImplementation: {
     ObjCImplementationDecl *OMD = cast<ObjCImplementationDecl>(D);
+    if (Features.ObjCNonFragileABI2 && OMD->hasSynthBitfield())
+      Context.ResetObjCLayout(OMD->getClassInterface());
     EmitObjCPropertyImplementations(OMD);
     EmitObjCIvarInitializations(OMD);
     Runtime->GenerateClass(OMD);

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=111823&r1=111822&r2=111823&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Aug 23 13:51:39 2010
@@ -6349,9 +6349,13 @@
   ObjCContainerDecl *EnclosingContext;
   if (ObjCImplementationDecl *IMPDecl =
       dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
+    if (!LangOpts.ObjCNonFragileABI2) {
     // Case of ivar declared in an implementation. Context is that of its class.
-    EnclosingContext = IMPDecl->getClassInterface();
-    assert(EnclosingContext && "Implementation has no class interface!");
+      EnclosingContext = IMPDecl->getClassInterface();
+      assert(EnclosingContext && "Implementation has no class interface!");
+    }
+    else
+      EnclosingContext = EnclosingDecl;
   } else {
     if (ObjCCategoryDecl *CDecl = 
         dyn_cast<ObjCCategoryDecl>(EnclosingDecl)) {

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=111823&r1=111822&r2=111823&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Mon Aug 23 13:51:39 2010
@@ -476,6 +476,7 @@
   CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
                       *Reader.getContext());
   CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
+  CD->setHasSynthBitfield(Record[Idx++]);
   CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 }
@@ -524,6 +525,7 @@
               cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
   llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
       = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx);
+  D->setHasSynthBitfield(Record[Idx++]);
 }
 
 

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=111823&r1=111822&r2=111823&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Mon Aug 23 13:51:39 2010
@@ -428,6 +428,7 @@
        PL != PLEnd; ++PL)
     Writer.AddSourceLocation(*PL, Record);
   Writer.AddDeclRef(D->getNextClassCategory(), Record);
+  Record.push_back(D->hasSynthBitfield());
   Writer.AddSourceLocation(D->getAtLoc(), Record);
   Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
   Code = serialization::DECL_OBJC_CATEGORY;
@@ -473,6 +474,7 @@
   Writer.AddDeclRef(D->getSuperClass(), Record);
   Writer.AddCXXBaseOrMemberInitializers(D->IvarInitializers,
                                         D->NumIvarInitializers, Record);
+  Record.push_back(D->hasSynthBitfield());
   Code = serialization::DECL_OBJC_IMPLEMENTATION;
 }
 

Added: cfe/trunk/test/CodeGenObjC/ivar-layout-nonfragile-abi2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/ivar-layout-nonfragile-abi2.m?rev=111823&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/ivar-layout-nonfragile-abi2.m (added)
+++ cfe/trunk/test/CodeGenObjC/ivar-layout-nonfragile-abi2.m Mon Aug 23 13:51:39 2010
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi2 -emit-llvm -o %t %s
+// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi2 -emit-llvm -o %t %s
+// rdar: // 7824380
+
+ at interface Super {
+  int ivar_super_a : 5;
+}
+ at end
+
+ at interface A : Super {
+ at public
+  int ivar_a : 5;
+}
+ at end
+
+int f0(A *a) {
+  return a->ivar_a;
+}
+
+ at interface A () {
+ at public
+  int ivar_ext_a : 5;
+  int ivar_ext_b : 5;
+}@end
+
+int f1(A *a) {
+  return a->ivar_ext_a + a->ivar_a;
+}
+
+ at interface A () {
+ at public
+  int ivar_ext2_a : 5;
+  int ivar_ext2_b : 5;
+}@end
+
+int f2(A* a) {
+  return a->ivar_ext2_a + a->ivar_ext_a + a->ivar_a;
+}
+
+ at implementation A {
+ at public
+  int ivar_b : 5;
+  int ivar_c : 5;
+  int ivar_d : 5;
+}
+ at end
+
+int f3(A *a) {  
+  return a->ivar_d + a->ivar_ext2_a + a->ivar_ext_a + a->ivar_a;
+}
+





More information about the cfe-commits mailing list