[cfe-commits] r69728 - in /cfe/trunk/lib: AST/ASTContext.cpp AST/DeclObjC.cpp CodeGen/CGObjCMac.cpp Sema/SemaDeclObjC.cpp

Daniel Dunbar daniel at zuster.org
Tue Apr 21 14:41:56 PDT 2009


Author: ddunbar
Date: Tue Apr 21 16:41:56 2009
New Revision: 69728

URL: http://llvm.org/viewvc/llvm-project?rev=69728&view=rev
Log:
Make sure to mark the interface as completed when we see an
@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.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

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

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Apr 21 16:41:56 2009
@@ -644,6 +644,9 @@
 /// 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'

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

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Tue Apr 21 16:41:56 2009
@@ -381,6 +381,7 @@
 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 =

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Tue Apr 21 16:41:56 2009
@@ -2564,11 +2564,7 @@
 /// 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 @@
 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(),

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Apr 21 16:41:56 2009
@@ -668,6 +668,11 @@
     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 = 





More information about the cfe-commits mailing list