[cfe-commits] r147498 - in /cfe/trunk: lib/AST/Decl.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaLookup.cpp test/Modules/Inputs/redecl-merge-left.h test/Modules/Inputs/redecl-merge-right.h test/Modules/redecl-merge.m

Douglas Gregor dgregor at apple.com
Tue Jan 3 15:26:26 PST 2012


Author: dgregor
Date: Tue Jan  3 17:26:26 2012
New Revision: 147498

URL: http://llvm.org/viewvc/llvm-project?rev=147498&view=rev
Log:
Test "merging" of typedef types across distinct modules. At present,
the AST reader doesn't actually perform a merge, because name lookup
knows how to merge identical typedefs together.

As part of this, teach C/Objective-C name lookup to return multiple
results in all cases, rather than first digging through the attributes
to see if the value is overloadable. This way, we'll catch ambiguous
lookups in C/Objective-C.

Modified:
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/Modules/Inputs/redecl-merge-left.h
    cfe/trunk/test/Modules/Inputs/redecl-merge-right.h
    cfe/trunk/test/Modules/redecl-merge.m

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=147498&r1=147497&r2=147498&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Tue Jan  3 17:26:26 2012
@@ -938,6 +938,12 @@
                                         cast<UsingDecl>(OldD)->getQualifier());
   }
 
+  // A typedef of an Objective-C class type can replace an Objective-C class
+  // declaration or definition, and vice versa.
+  if ((isa<TypedefNameDecl>(this) && isa<ObjCInterfaceDecl>(OldD)) ||
+      (isa<ObjCInterfaceDecl>(this) && isa<TypedefNameDecl>(OldD)))
+    return true;
+  
   // For non-function declarations, if the declarations are of the
   // same kind then this must be a redeclaration, or semantic analysis
   // would not have given us the new declaration.

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=147498&r1=147497&r2=147498&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jan  3 17:26:26 2012
@@ -8010,8 +8010,6 @@
     // lookup.  This is only actually possible in C++, where a few
     // things like templates still live in the tag namespace.
     } else {
-      assert(getLangOptions().CPlusPlus);
-
       // Use a better diagnostic if an elaborated-type-specifier
       // found the wrong kind of type on the first
       // (non-redeclaration) lookup.

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=147498&r1=147497&r2=147498&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Jan  3 17:26:26 2012
@@ -1177,30 +1177,31 @@
                 
         R.addDecl(D);
 
-        if ((*I)->getAttr<OverloadableAttr>()) {
-          // If this declaration has the "overloadable" attribute, we
-          // might have a set of overloaded functions.
-
-          // Figure out what scope the identifier is in.
-          while (!(S->getFlags() & Scope::DeclScope) ||
-                 !S->isDeclScope(*I))
-            S = S->getParent();
-
-          // Find the last declaration in this scope (with the same
-          // name, naturally).
-          IdentifierResolver::iterator LastI = I;
-          for (++LastI; LastI != IEnd; ++LastI) {
-            if (!S->isDeclScope(*LastI))
-              break;
-            
-            D = getVisibleDecl(*LastI);
-            if (D)
-              R.addDecl(D);
-          }
+        // Check whether there are any other declarations with the same name
+        // and in the same scope.
+
+        // Figure out what scope the identifier is in.
+        while (S->getParent() &&
+               (!(S->getFlags() & Scope::DeclScope) ||
+                !S->isDeclScope(*I)))
+          S = S->getParent();
+
+        // Find the last declaration in this scope (with the same
+        // name, naturally).
+        IdentifierResolver::iterator LastI = I;
+        for (++LastI; LastI != IEnd; ++LastI) {
+          if (!S->isDeclScope(*LastI))
+            break;
+          
+          if (!(*LastI)->isInIdentifierNamespace(IDNS))
+            continue;
+          
+          D = getVisibleDecl(*LastI);
+          if (D)
+            R.addDecl(D);
         }
 
         R.resolveKind();
-
         return true;
       }
   } else {

Modified: cfe/trunk/test/Modules/Inputs/redecl-merge-left.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/redecl-merge-left.h?rev=147498&r1=147497&r2=147498&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/redecl-merge-left.h (original)
+++ cfe/trunk/test/Modules/Inputs/redecl-merge-left.h Tue Jan  3 17:26:26 2012
@@ -56,6 +56,9 @@
 struct S3 *produce_S3(void);
 void consume_S4(struct S4*);
 
+typedef int T1;
+typedef float T2;
+
 #ifdef __cplusplus
 template<typename T> class Vector;
 

Modified: cfe/trunk/test/Modules/Inputs/redecl-merge-right.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/redecl-merge-right.h?rev=147498&r1=147497&r2=147498&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/redecl-merge-right.h (original)
+++ cfe/trunk/test/Modules/Inputs/redecl-merge-right.h Tue Jan  3 17:26:26 2012
@@ -59,6 +59,9 @@
 void consume_S3(struct S3*);
 struct S4 *produce_S4(void);
 
+typedef int T1;
+typedef double T2;
+
 #ifdef __cplusplus
 template<typename T> class Vector { 
 public:

Modified: cfe/trunk/test/Modules/redecl-merge.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/redecl-merge.m?rev=147498&r1=147497&r2=147498&view=diff
==============================================================================
--- cfe/trunk/test/Modules/redecl-merge.m (original)
+++ cfe/trunk/test/Modules/redecl-merge.m Tue Jan  3 17:26:26 2012
@@ -55,6 +55,15 @@
   s3.s3_field = 0;
 }
 
+void testTypedefMerge(int i, double d) {
+  T1 *ip = &i;
+  // in other file: expected-note{{candidate found by name lookup is 'T2'}}
+  // FIXME: Typedefs aren't actually merged in the sense of other merges, because
+  // we should only merge them when the types are identical.
+  // in other file: expected-note{{candidate found by name lookup is 'T2'}}
+  T2 *dp = &d; // expected-error{{reference to 'T2' is ambiguous}}
+}
+
 // Test redeclarations of entities in explicit submodules, to make
 // sure we're maintaining the declaration chains even when normal name
 // lookup can't see what we're looking for.





More information about the cfe-commits mailing list