]> granicus.if.org Git - clang/commitdiff
Make sure to mark the interface as completed when we see an
authorDaniel Dunbar <daniel@zuster.org>
Tue, 21 Apr 2009 21:41:56 +0000 (21:41 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 21 Apr 2009 21:41:56 +0000 (21:41 +0000)
@implementation that closes a @class delcaration.
 - I don't know how to make a test case for this, but this strengthens
   the invariants that hold internally. The functionality change here
   is the edit to SemaDeclObjC.cpp.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69728 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
lib/AST/DeclObjC.cpp
lib/CodeGen/CGObjCMac.cpp
lib/Sema/SemaDeclObjC.cpp

index cfff4b54402cabae6aa074c21307bf627b1b41a9..c4597e2235e4e4d056de195d99e9bf30000acad7 100644 (file)
@@ -644,6 +644,9 @@ void ASTContext::CollectObjCIvars(const ObjCInterfaceDecl *OI,
 /// 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 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'
index 9cc22912caff687dba65a144c32cf164cfbd7abc..5df5ff3a7ad0bfa23fa1f8d57098cfd403ec1393 100644 (file)
@@ -381,6 +381,7 @@ ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
 const FieldDecl *
 ObjCInterfaceDecl::lookupFieldDeclForIvar(ASTContext &Context, 
                                           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 =
index ed71b09942b49e52734b2db1749a4c179cb7017d..de29427c0e976ff110331aed17c858affe5565a3 100644 (file)
@@ -2564,11 +2564,7 @@ llvm::Constant *CGObjCCommonMac::GetClassName(IdentifierInfo *Ident) {
 /// interface declaration.
 const llvm::StructLayout *CGObjCCommonMac::GetInterfaceDeclStructLayout(
                                         const ObjCInterfaceDecl *OID) const {
-  // FIXME: When does this happen? It seems pretty bad to do this...
-  if (OID->isForwardDecl())
-    return CGM.getTargetData().getStructLayout(llvm::StructType::get(NULL, 
-                                                                     NULL));
-
+  assert(!OID->isForwardDecl() && "Invalid interface decl!");
   QualType T = 
     CGM.getContext().getObjCInterfaceType(const_cast<ObjCInterfaceDecl*>(OID));
   const llvm::StructType *InterfaceTy = 
@@ -4231,6 +4227,7 @@ static int countInheritedIvars(const ObjCInterfaceDecl *OI,
 void CGObjCNonFragileABIMac::GetClassSizeInfo(const ObjCInterfaceDecl *OID,
                                               uint32_t &InstanceStart,
                                               uint32_t &InstanceSize) {
+  assert(!OID->isForwardDecl() && "Invalid interface decl!");
   const llvm::StructLayout *Layout = GetInterfaceDeclStructLayout(OID);
     
   int countSuperClassIvars = countInheritedIvars(OID->getSuperClass(),
index 5ab1efec0374af2bd70cb5c501e751f7e861a0b0..2874f27cd3b3658b63a25911933550bb920f449c 100644 (file)
@@ -668,6 +668,11 @@ Sema::DeclPtrTy Sema::ActOnStartClassImplementation(
     CurContext->addDecl(Context, IDecl);
     // Remember that this needs to be removed when the scope is popped.
     TUScope->AddDecl(DeclPtrTy::make(IDecl));
+  } else {
+    // Mark the interface as being completed, even if it was just as
+    //   @class ....;
+    // declaration; the user cannot reopen it.
+    IDecl->setForwardDecl(false);
   }
   
   ObjCImplementationDecl* IMPDecl =