Revert r69771, I missed some (obvious) details. :/

llvm-svn: 69773
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index af7cf12..f156ac4 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -621,9 +621,11 @@
   Alignment = std::max(Alignment, FieldAlign);
 }
 
-static void CollectLocalObjCIvars(ASTContext *Ctx,
-                                  const ObjCInterfaceDecl *OI,
-                                  llvm::SmallVectorImpl<FieldDecl*> &Fields) {
+void ASTContext::CollectObjCIvars(const ObjCInterfaceDecl *OI,
+                             llvm::SmallVectorImpl<FieldDecl*> &Fields) {
+  const ObjCInterfaceDecl *SuperClass = OI->getSuperClass();
+  if (SuperClass)
+    CollectObjCIvars(SuperClass, Fields);
   for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
        E = OI->ivar_end(); I != E; ++I) {
     ObjCIvarDecl *IVDecl = *I;
@@ -631,28 +633,20 @@
       Fields.push_back(cast<FieldDecl>(IVDecl));
   }
   // look into properties.
-  for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(*Ctx),
-       E = OI->prop_end(*Ctx); I != E; ++I) {
+  for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(*this),
+       E = OI->prop_end(*this); I != E; ++I) {
     if (ObjCIvarDecl *IV = (*I)->getPropertyIvarDecl())
       Fields.push_back(cast<FieldDecl>(IV));
   }
 }
 
-
-void ASTContext::CollectObjCIvars(const ObjCInterfaceDecl *OI,
-                             llvm::SmallVectorImpl<FieldDecl*> &Fields) {
-  if (const ObjCInterfaceDecl *SuperClass = OI->getSuperClass())
-    CollectObjCIvars(SuperClass, Fields);
-  CollectLocalObjCIvars(this, OI, Fields);
-}
-
 /// addRecordToClass - produces record info. for the class for its
 /// ivars and all those inherited.
 ///
 const RecordDecl *ASTContext::addRecordToClass(const ObjCInterfaceDecl *D) {
   // FIXME: The only client relying on this working in the presence of
-  // forward declarations is CodeGenTypes in IRgen, which should not
-  // need it. Fix and simplify this code.
+  // forward declarations is IRgen, which should not need it. Fix
+  // and simplify this code.
   RecordDecl *&RD = ASTRecordForInterface[D];
   if (RD) {
     // If we have a record decl already and it is either a definition or if 'D'
@@ -668,28 +662,11 @@
                                    D->getIdentifier());
   
   llvm::SmallVector<FieldDecl*, 32> RecFields;
-  CollectLocalObjCIvars(this, D, RecFields);
+  CollectObjCIvars(D, RecFields);
   
   if (RD == 0)
     RD = RecordDecl::Create(*this, TagDecl::TK_struct, 0, D->getLocation(),
                             D->getIdentifier());
-
-  
-  const RecordDecl *SRD;
-  if (const ObjCInterfaceDecl *SuperClass = D->getSuperClass()) {
-    SRD = addRecordToClass(SuperClass);
-  } else {
-    SRD = RecordDecl::Create(*this, TagDecl::TK_struct, 0, SourceLocation(), 0);
-    const_cast<RecordDecl*>(SRD)->completeDefinition(*this);
-  }
-
-  RD->addDecl(*this, 
-              FieldDecl::Create(*this, RD,
-                                SourceLocation(),
-                                0,
-                                getTagDeclType(const_cast<RecordDecl*>(SRD)),
-                                0, false));
-
   /// FIXME! Can do collection of ivars and adding to the record while
   /// doing it.
   for (unsigned i = 0, e = RecFields.size(); i != e; ++i) {
diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp
index de10230..d9bec6d 100644
--- a/clang/lib/AST/DeclObjC.cpp
+++ b/clang/lib/AST/DeclObjC.cpp
@@ -380,32 +380,14 @@
 ///
 const FieldDecl *
 ObjCInterfaceDecl::lookupFieldDeclForIvar(ASTContext &Context, 
-                                          const ObjCIvarDecl *OIVD) const {
+                                          const ObjCIvarDecl *IVar) const {
   assert(!isForwardDecl() && "Invalid interface decl!");
   const RecordDecl *RecordForDecl = Context.addRecordToClass(this);
+  assert(RecordForDecl && "lookupFieldDeclForIvar no storage for class");
   DeclContext::lookup_const_result Lookup =
-    RecordForDecl->lookup(Context, OIVD->getDeclName());
-
-  if (Lookup.first != Lookup.second)
-    return cast<FieldDecl>(*Lookup.first);
-
-  // If lookup failed, try the superclass.
-  //
-  // FIXME: This is very non-performant. However, the root problem
-  // here is not the lookup itself. The main issue is that we should
-  // be able to map from an IvarDecl back to the context it lives
-  // inside; then this problem goes away. Currently, however,
-  // IvarDecl's live inside the translation unit!!!!
-  //
-  // Fixing IvarDecl's is less obvious than it might appear, we need
-  // to choose where synthesized ivars should live, and we also need
-  // to decide where to put IvarDecl's which appeared in an
-  // implementation context (either in the situation where they must
-  // duplicate the instance variables, or if there was no instance
-  // declaration).
-  const ObjCInterfaceDecl *OID = getSuperClass();
-  assert(OID && "field decl not found!");
-  return OID->lookupFieldDeclForIvar(Context, OIVD);
+    RecordForDecl->lookup(Context, IVar->getDeclName());
+  assert((Lookup.first != Lookup.second) && "field decl not found");
+  return cast<FieldDecl>(*Lookup.first);
 }
 
 //===----------------------------------------------------------------------===//