[cfe-commits] r96638 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/DeclObjC.h lib/AST/ASTContext.cpp lib/AST/RecordLayoutBuilder.cpp lib/CodeGen/CGObjCMac.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/RewriteObjC.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclObjC.cpp test/CodeGenObjC/stand-alone-implementation.m

Fariborz Jahanian fjahanian at apple.com
Thu Feb 18 16:31:17 PST 2010


Author: fjahanian
Date: Thu Feb 18 18:31:17 2010
New Revision: 96638

URL: http://llvm.org/viewvc/llvm-project?rev=96638&view=rev
Log:
Patch removes IVars list from ObjCInterfaceDecl and
instead relies on their DeclContext for iteration, etc.


Added:
    cfe/trunk/test/CodeGenObjC/stand-alone-implementation.m
Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Frontend/RewriteObjC.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=96638&r1=96637&r2=96638&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Feb 18 18:31:17 2010
@@ -882,9 +882,8 @@
                         llvm::SmallVectorImpl<FieldDecl*> &Fields);
 
   void ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI,
-                               llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars,
-                               bool CollectSynthesized = true);
-  void CollectSynthesizedIvars(const ObjCInterfaceDecl *OI,
+                               llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
+  void CollectNonClassIvars(const ObjCInterfaceDecl *OI,
                                llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
   void CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
                                llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=96638&r1=96637&r2=96638&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Feb 18 18:31:17 2010
@@ -494,11 +494,13 @@
   }
   unsigned protocol_size() const { return ReferencedProtocols.size(); }
 
-  typedef ObjCList<ObjCIvarDecl>::iterator ivar_iterator;
-  ivar_iterator ivar_begin() const { return IVars.begin(); }
-  ivar_iterator ivar_end() const { return IVars.end(); }
-  unsigned ivar_size() const { return IVars.size(); }
-  bool ivar_empty() const { return IVars.empty(); }
+  typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
+  ivar_iterator ivar_begin() const { return  ivar_iterator(decls_begin()); }
+  ivar_iterator ivar_end() const { return ivar_iterator(decls_end()); }
+  unsigned ivar_size() const {
+    return std::distance(ivar_begin(), ivar_end());
+  }
+  bool ivar_empty() const { return ivar_begin() == ivar_end(); }
 
   /// setProtocolList - Set the list of protocols that this interface
   /// implements.
@@ -514,10 +516,6 @@
                                        const SourceLocation *Locs,
                                        ASTContext &C);
 
-  void setIVarList(ObjCIvarDecl * const *List, unsigned Num, ASTContext &C) {
-    IVars.set(List, Num, C);
-  }
-
   bool isForwardDecl() const { return ForwardDecl; }
   void setForwardDecl(bool val) { ForwardDecl = val; }
 

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=96638&r1=96637&r2=96638&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Feb 18 18:31:17 2010
@@ -872,14 +872,13 @@
 /// Collect all ivars, including those synthesized, in the current class.
 ///
 void ASTContext::ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI,
-                                 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars,
-                                 bool CollectSynthesized) {
+                                 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) {
   for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
          E = OI->ivar_end(); I != E; ++I) {
      Ivars.push_back(*I);
   }
-  if (CollectSynthesized)
-    CollectSynthesizedIvars(OI, Ivars);
+
+  CollectNonClassIvars(OI, Ivars);
 }
 
 void ASTContext::CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
@@ -895,10 +894,11 @@
     CollectProtocolSynthesizedIvars(*P, Ivars);
 }
 
-/// CollectSynthesizedIvars -
-/// This routine collect synthesized ivars for the designated class.
+/// CollectNonClassIvars -
+/// This routine collects all other ivars which are not declared in the class.
+/// This includes synthesized ivars and those in class's implementation.
 ///
-void ASTContext::CollectSynthesizedIvars(const ObjCInterfaceDecl *OI,
+void ASTContext::CollectNonClassIvars(const ObjCInterfaceDecl *OI,
                                 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) {
   for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(),
        E = OI->prop_end(); I != E; ++I) {
@@ -912,6 +912,13 @@
     ObjCProtocolDecl *PD = (*P);
     CollectProtocolSynthesizedIvars(PD, Ivars);
   }
+
+  // Also add any ivar defined in this class's implementation
+  if (ObjCImplementationDecl *ImplDecl = OI->getImplementation()) {
+    for (ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(),
+         E = ImplDecl->ivar_end(); I != E; ++I)
+      Ivars.push_back(*I);
+  }
 }
 
 /// CollectInheritedProtocols - Collect all protocols in current class and

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=96638&r1=96637&r2=96638&view=diff

==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Thu Feb 18 18:31:17 2010
@@ -487,6 +487,7 @@
   FinishLayout();
 }
 
+// FIXME. Impl is no longer needed.
 void ASTRecordLayoutBuilder::Layout(const ObjCInterfaceDecl *D,
                                     const ObjCImplementationDecl *Impl) {
   if (ObjCInterfaceDecl *SD = D->getSuperClass()) {
@@ -508,10 +509,9 @@
 
   if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
     UpdateAlignment(AA->getMaxAlignment());
-
   // Layout each ivar sequentially.
   llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
-  Ctx.ShallowCollectObjCIvars(D, Ivars, Impl);
+  Ctx.ShallowCollectObjCIvars(D, Ivars);
   for (unsigned i = 0, e = Ivars.size(); i != e; ++i)
     LayoutField(Ivars[i]);
 

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=96638&r1=96637&r2=96638&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Thu Feb 18 18:31:17 2010
@@ -3293,7 +3293,7 @@
 
   // Add this implementations synthesized ivars.
   llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
-  CGM.getContext().CollectSynthesizedIvars(OI, Ivars);
+  CGM.getContext().CollectNonClassIvars(OI, Ivars);
   for (unsigned k = 0, e = Ivars.size(); k != e; ++k)
     RecFields.push_back(cast<FieldDecl>(Ivars[k]));
 

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=96638&r1=96637&r2=96638&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Thu Feb 18 18:31:17 2010
@@ -235,7 +235,6 @@
   IVars.reserve(NumIvars);
   for (unsigned I = 0; I != NumIvars; ++I)
     IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
-  ID->setIVarList(IVars.data(), NumIvars, *Reader.getContext());
   ID->setCategoryList(
                cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
   ID->setForwardDecl(Record[Idx++]);

Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=96638&r1=96637&r2=96638&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Thu Feb 18 18:31:17 2010
@@ -3534,12 +3534,12 @@
     ObjCInterfaceDecl::ivar_iterator IVI, IVE;
     llvm::SmallVector<ObjCIvarDecl *, 8> IVars;
     if (!IDecl->ivar_empty()) {
-      for (ObjCImplementationDecl::ivar_iterator
+      for (ObjCInterfaceDecl::ivar_iterator
              IV = IDecl->ivar_begin(), IVEnd = IDecl->ivar_end();
            IV != IVEnd; ++IV)
         IVars.push_back(*IV);
-      IVI = IVars.begin();
-      IVE = IVars.end();
+      IVI = IDecl->ivar_begin();
+      IVE = IDecl->ivar_end();
     } else {
       IVI = CDecl->ivar_begin();
       IVE = CDecl->ivar_end();

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=96638&r1=96637&r2=96638&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Feb 18 18:31:17 2010
@@ -5641,7 +5641,6 @@
     ObjCIvarDecl **ClsFields =
       reinterpret_cast<ObjCIvarDecl**>(RecFields.data());
     if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(EnclosingDecl)) {
-      ID->setIVarList(ClsFields, RecFields.size(), Context);
       ID->setLocEnd(RBrac);
       // Add ivar's to class's DeclContext.
       for (unsigned i = 0, e = RecFields.size(); i != e; ++i) {

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=96638&r1=96637&r2=96638&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Feb 18 18:31:17 2010
@@ -821,12 +821,12 @@
   /// (legacy objective-c @implementation decl without an @interface decl).
   /// Add implementations's ivar to the synthesize class's ivar list.
   if (IDecl->isImplicitInterfaceDecl()) {
-    IDecl->setIVarList(ivars, numIvars, Context);
     IDecl->setLocEnd(RBrace);
     // Add ivar's to class's DeclContext.
     for (unsigned i = 0, e = numIvars; i != e; ++i) {
       ivars[i]->setLexicalDeclContext(ImpDecl);
       IDecl->makeDeclVisibleInContext(ivars[i], false);
+      ImpDecl->addDecl(ivars[i]);
     }
     
     return;
@@ -2446,8 +2446,7 @@
                                   PropertyIvar, PropType, /*Dinfo=*/0,
                                   ObjCIvarDecl::Public,
                                   (Expr *)0);
-      Ivar->setLexicalDeclContext(IDecl);
-      IDecl->addDecl(Ivar);
+      IDecl->makeDeclVisibleInContext(Ivar, false);
       property->setPropertyIvarDecl(Ivar);
       if (!getLangOptions().ObjCNonFragileABI)
         Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId;

Added: cfe/trunk/test/CodeGenObjC/stand-alone-implementation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/stand-alone-implementation.m?rev=96638&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/stand-alone-implementation.m (added)
+++ cfe/trunk/test/CodeGenObjC/stand-alone-implementation.m Thu Feb 18 18:31:17 2010
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fobjc-nonfragile-abi -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-X86-64 %s
+
+// radar 7547942
+// Allow injection of ivars into implementation's implicit class.
+
+ at implementation INTFSTANDALONE // expected-warning {{cannot find interface declaration for 'INTFSTANDALONE'}}
+{
+  id IVAR1;
+  id IVAR2;
+}
+- (id) Meth { return IVAR1; }
+ at end
+
+// CHECK-X86-64: @"OBJC_IVAR_$_INTFSTANDALONE.IVAR1"
+// CHECK-X86-64: @"OBJC_IVAR_$_INTFSTANDALONE.IVAR2"
+





More information about the cfe-commits mailing list