[cfe-commits] r43000 - in /cfe/trunk: Sema/SemaDecl.cpp test/Sema/check-dup-objc-decls-1.m test/Sema/class-def-test-1.m

Fariborz Jahanian fjahanian at apple.com
Mon Oct 15 12:16:58 PDT 2007


Author: fjahanian
Date: Mon Oct 15 14:16:57 2007
New Revision: 43000

URL: http://llvm.org/viewvc/llvm-project?rev=43000&view=rev
Log:
Several name lookup conflict detection fixes involving objective-c names.

Added:
    cfe/trunk/test/Sema/check-dup-objc-decls-1.m
Modified:
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/class-def-test-1.m

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Mon Oct 15 14:16:57 2007
@@ -945,6 +945,9 @@
     // Chain & install the interface decl into the identifier.
     IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
     ClassName->setFETokenInfo(IDecl);
+    
+    // Remember that this needs to be removed when the scope is popped.
+    TUScope->AddDecl(IDecl);
   }
   
   if (SuperName) {
@@ -1214,6 +1217,8 @@
     IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
     ClassName->setFETokenInfo(IDecl);
     
+    // Remember that this needs to be removed when the scope is popped.
+    TUScope->AddDecl(IDecl);
   }
   
   // Check that there is no duplicate implementation of this class.
@@ -1397,9 +1402,16 @@
   llvm::SmallVector<ObjcInterfaceDecl*, 32> Interfaces;
   
   for (unsigned i = 0; i != NumElts; ++i) {
-    ObjcInterfaceDecl *IDecl = getObjCInterfaceDecl(IdentList[i]); 
+    // Check for another declaration kind with the same name.
+    ScopedDecl *PrevDecl = LookupInterfaceDecl(IdentList[i]);
+    if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)) {
+      Diag(AtClassLoc, diag::err_redefinition_different_kind,
+           IdentList[i]->getName());
+      Diag(PrevDecl->getLocation(), diag::err_previous_definition);
+    }
+    ObjcInterfaceDecl *IDecl = dyn_cast_or_null<ObjcInterfaceDecl>(PrevDecl); 
     if (!IDecl) {  // Not already seen?  Make a forward decl.
-      IDecl = new ObjcInterfaceDecl(SourceLocation(), 0, IdentList[i], true);
+      IDecl = new ObjcInterfaceDecl(AtClassLoc, 0, IdentList[i], true);
       // Chain & install the interface decl into the identifier.
       IDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
       IdentList[i]->setFETokenInfo(IDecl);

Added: cfe/trunk/test/Sema/check-dup-objc-decls-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/check-dup-objc-decls-1.m?rev=43000&view=auto

==============================================================================
--- cfe/trunk/test/Sema/check-dup-objc-decls-1.m (added)
+++ cfe/trunk/test/Sema/check-dup-objc-decls-1.m Mon Oct 15 14:16:57 2007
@@ -0,0 +1,29 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at interface Foo // expected-error {{previous definition is here}}
+ at end
+
+float Foo;	// expected-error {{redefinition of 'Foo' as different kind of symbol}}
+
+ at class Bar;  // expected-error {{previous definition is here}}
+
+typedef int Bar;  // expected-error {{redefinition of 'Bar' as different kind of symbol}}
+
+ at implementation FooBar // expected-warning {{cannot find interface declaration for 'FooBar'}} 
+ at end
+
+
+typedef int OBJECT; // expected-error {{previous definition is here}}
+
+ at class OBJECT ;	// expected-error {{redefinition of 'OBJECT' as different kind of symbol}}
+
+
+typedef int Gorf;  // expected-error {{previous definition is here}}
+
+ at interface Gorf @end // expected-error {{redefinition of 'Gorf' as different kind of symbol}} \
+		     // expected-error {{previous definition is here}}
+
+void Gorf() // expected-error {{redefinition of 'Gorf' as different kind of symbol}}
+{
+	int Bar, Foo, FooBar;
+}

Modified: cfe/trunk/test/Sema/class-def-test-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/class-def-test-1.m?rev=43000&r1=42999&r2=43000&view=diff

==============================================================================
--- cfe/trunk/test/Sema/class-def-test-1.m (original)
+++ cfe/trunk/test/Sema/class-def-test-1.m Mon Oct 15 14:16:57 2007
@@ -8,13 +8,14 @@
 
 @interface INTF @end // expected-error {{redefinition of 'INTF' as different kind of symbol}}
 
- at interface OBJECT @end
+ at interface OBJECT @end	// expected-error {{previous definition is here}}
 
 @interface INTF1 : OBJECT @end
 
 @interface INTF1 : OBJECT @end // expected-error {{duplicate interface declaration for class 'INTF1'}
 
-typedef int OBJECT; // expected-error {{previous definition is here}}
+typedef int OBJECT; // expected-error {{previous definition is here}}  \
+		       expected-error {{redefinition of 'OBJECT' as different kind of symbol}}
 
 @interface INTF2 : OBJECT @end // expected-error {{redefinition of 'OBJECT' as different kind of symbol}}
 





More information about the cfe-commits mailing list