[cfe-commits] r65340 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclObjC.cpp test/Sema/anonymous-struct-union.c test/Sema/nested-redef.c test/SemaObjC/interface-1.m test/SemaObjC/ivar-sem-check-1.m

Chris Lattner sabre at nondot.org
Mon Feb 23 14:00:09 PST 2009


Author: lattner
Date: Mon Feb 23 16:00:08 2009
New Revision: 65340

URL: http://llvm.org/viewvc/llvm-project?rev=65340&view=rev
Log:
fix rdar://6611778, a redefinition of an interface was causing an
assertion when the ivars and method list was reset into the existing
interface.  To fix this, mark decls as invalid when they are redefined,
and don't insert ivars/methods into invalid decls.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/Sema/anonymous-struct-union.c
    cfe/trunk/test/Sema/nested-redef.c
    cfe/trunk/test/SemaObjC/interface-1.m
    cfe/trunk/test/SemaObjC/ivar-sem-check-1.m

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Feb 23 16:00:08 2009
@@ -3665,12 +3665,20 @@
                        AttributeList *Attr) {
   Decl *EnclosingDecl = static_cast<Decl*>(RecDecl);
   assert(EnclosingDecl && "missing record or interface decl");
-  RecordDecl *Record = dyn_cast<RecordDecl>(EnclosingDecl);
+  
+  // If the decl this is being inserted into is invalid, then it may be a
+  // redeclaration or some other bogus case.  Don't try to add fields to it.
+  if (EnclosingDecl->isInvalidDecl()) {
+    // FIXME: Deallocate fields?
+    return;
+  }
+
   
   // Verify that all the fields are okay.
   unsigned NumNamedMembers = 0;
   llvm::SmallVector<FieldDecl*, 32> RecFields;
 
+  RecordDecl *Record = dyn_cast<RecordDecl>(EnclosingDecl);
   for (unsigned i = 0; i != NumFields; ++i) {
     FieldDecl *FD = cast_or_null<FieldDecl>(static_cast<Decl*>(Fields[i]));
     assert(FD && "missing field decl");
@@ -3782,9 +3790,8 @@
           }
         }
       }
-    }
-    else if (ObjCImplementationDecl *IMPDecl = 
-               dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
+    } else if (ObjCImplementationDecl *IMPDecl = 
+                  dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
       assert(IMPDecl && "ActOnFields - missing ObjCImplementationDecl");
       IMPDecl->setIVarList(ClsFields, RecFields.size(), Context);
       CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac);

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Feb 23 16:00:08 2009
@@ -78,6 +78,7 @@
   if (IDecl) {
     // Class already seen. Is it a forward declaration?
     if (!IDecl->isForwardDecl()) {
+      IDecl->setInvalidDecl();
       Diag(AtInterfaceLoc, diag::err_duplicate_class_def)<<IDecl->getDeclName();
       Diag(IDecl->getLocation(), diag::note_previous_definition);
 
@@ -225,6 +226,7 @@
   if (PDecl) {
     // Protocol already seen. Better be a forward protocol declaration
     if (!PDecl->isForwardDecl()) {
+      PDecl->setInvalidDecl();
       Diag(ProtocolLoc, diag::err_duplicate_protocol_def) << ProtocolName;
       Diag(PDecl->getLocation(), diag::note_previous_definition);
       // Just return the protocol we already had.
@@ -555,8 +557,7 @@
   if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
     Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
     Diag(PrevDecl->getLocation(), diag::note_previous_definition);
-  }
-  else {
+  }  else {
     // Is there an interface declaration of this class; if not, warn!
     IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); 
     if (!IDecl)

Modified: cfe/trunk/test/Sema/anonymous-struct-union.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/anonymous-struct-union.c?rev=65340&r1=65339&r2=65340&view=diff

==============================================================================
--- cfe/trunk/test/Sema/anonymous-struct-union.c (original)
+++ cfe/trunk/test/Sema/anonymous-struct-union.c Mon Feb 23 16:00:08 2009
@@ -47,8 +47,7 @@
   };
 
   int z; // expected-error{{duplicate member 'z'}}
-  void zz(); // expected-error{{duplicate member 'zz'}} \
-            //  expected-error{{field 'zz' declared as a function}}
+  void zz(); // expected-error{{duplicate member 'zz'}} 
 };
 
 union { // expected-error{{anonymous unions must be struct or union members}}

Modified: cfe/trunk/test/Sema/nested-redef.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/nested-redef.c?rev=65340&r1=65339&r2=65340&view=diff

==============================================================================
--- cfe/trunk/test/Sema/nested-redef.c (original)
+++ cfe/trunk/test/Sema/nested-redef.c Mon Feb 23 16:00:08 2009
@@ -1,6 +1,7 @@
 // RUN: clang -fsyntax-only -verify %s
 struct X { // expected-note{{previous definition is here}}
-  struct X { } x; // expected-error{{nested redefinition of 'X'}}
+  struct X { } x; // expected-error{{nested redefinition of 'X'}} \
+                     expected-error {{field has incomplete type}}
 }; 
 
 struct Y { };

Modified: cfe/trunk/test/SemaObjC/interface-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/interface-1.m?rev=65340&r1=65339&r2=65340&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/interface-1.m (original)
+++ cfe/trunk/test/SemaObjC/interface-1.m Mon Feb 23 16:00:08 2009
@@ -25,3 +25,13 @@
     ++c;
 }
 
+
+// rdar://6611778
+ at interface FOO  // expected-note {{previous definition is here}}
+- (void)method;
+ at end
+
+ at interface FOO  // expected-error {{duplicate interface definition for class 'FOO'}}
+- (void)method2;
+ at end
+

Modified: cfe/trunk/test/SemaObjC/ivar-sem-check-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ivar-sem-check-1.m?rev=65340&r1=65339&r2=65340&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/ivar-sem-check-1.m (original)
+++ cfe/trunk/test/SemaObjC/ivar-sem-check-1.m Mon Feb 23 16:00:08 2009
@@ -9,7 +9,8 @@
 	int arr[];  // expected-error {{field has incomplete type}}
 	struct S IC;  // expected-error {{field has incomplete type}}
 	struct T { // expected-note {{previous definition is here}}
-	  struct T {} X;  // expected-error {{nested redefinition of 'T'}}
+	  struct T {} X;  // expected-error {{nested redefinition of 'T'}} \
+                             expected-error {{field has incomplete type}}
 	}YYY; 
 	FOO    BADFUNC;  // expected-error {{field 'BADFUNC' declared as a function}}
 	int kaka;	// expected-note {{previous declaration is here}}





More information about the cfe-commits mailing list