]> granicus.if.org Git - clang/commitdiff
Whenever Sema attempts to look in the global method pool, try to load
authorDouglas Gregor <dgregor@apple.com>
Wed, 25 Jan 2012 00:59:09 +0000 (00:59 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 25 Jan 2012 00:59:09 +0000 (00:59 +0000)
additional data from the external Sema source. This properly copes
with modules that are imported after we have already searched in the
global method pool for a given selector. For PCH, it's a slight
pessimization to be fixed soon.

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

lib/Sema/SemaDeclObjC.cpp
test/Modules/Inputs/MethodPoolA.h [new file with mode: 0644]
test/Modules/Inputs/MethodPoolB.h [new file with mode: 0644]
test/Modules/Inputs/module.map
test/Modules/method_pool.m [new file with mode: 0644]

index 432e3ddf54769a20a12997318d24c74cc16afdca..4394dbf9be1cc8f94f94e9bb1b981dbc73a8bfd4 100644 (file)
@@ -1983,17 +1983,13 @@ void Sema::ReadMethodPool(Selector Sel) {
 
 void Sema::AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl,
                                  bool instance) {
+  if (ExternalSource)
+    ReadMethodPool(Method->getSelector());
+  
   GlobalMethodPool::iterator Pos = MethodPool.find(Method->getSelector());
-  if (Pos == MethodPool.end()) {
-    if (ExternalSource) {
-      ReadMethodPool(Method->getSelector());
-      Pos = MethodPool.find(Method->getSelector());
-    }
-    
-    if (Pos == MethodPool.end())
-      Pos = MethodPool.insert(std::make_pair(Method->getSelector(),
-                                             GlobalMethods())).first;
-  }
+  if (Pos == MethodPool.end())
+    Pos = MethodPool.insert(std::make_pair(Method->getSelector(),
+                                           GlobalMethods())).first;
   
   Method->setDefined(impl);
   
@@ -2023,18 +2019,12 @@ static bool isAcceptableMethodMismatch(ObjCMethodDecl *chosen,
 ObjCMethodDecl *Sema::LookupMethodInGlobalPool(Selector Sel, SourceRange R,
                                                bool receiverIdOrClass,
                                                bool warn, bool instance) {
+  if (ExternalSource)
+    ReadMethodPool(Sel);
+    
   GlobalMethodPool::iterator Pos = MethodPool.find(Sel);
-  if (Pos == MethodPool.end()) {
-    if (ExternalSource) {
-      ReadMethodPool(Sel);
-      
-      Pos = MethodPool.find(Sel);
-      if (Pos == MethodPool.end())
-        return 0;
-      
-    } else
-      return 0;
-  }
+  if (Pos == MethodPool.end())
+    return 0;
 
   ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second;
 
diff --git a/test/Modules/Inputs/MethodPoolA.h b/test/Modules/Inputs/MethodPoolA.h
new file mode 100644 (file)
index 0000000..6af24a9
--- /dev/null
@@ -0,0 +1,8 @@
+
+
+
+
+@interface A
++ (int)method1;
+- (int)method2:(int)param;
+@end
diff --git a/test/Modules/Inputs/MethodPoolB.h b/test/Modules/Inputs/MethodPoolB.h
new file mode 100644 (file)
index 0000000..e1e86ed
--- /dev/null
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+@interface B
+- (int)method1;
+- (int)method2:(float)param;
+@end
index 2819e62b8f118fe4f0edb67f364b07430b3ab4f0..e09073f818cd540c2837e062c437b829cc7fb58e 100644 (file)
@@ -75,3 +75,9 @@ module namespaces_right {
   header "namespaces-right.h"
   export *
 }
+module MethodPoolA {
+  header "MethodPoolA.h"
+}
+module MethodPoolB {
+  header "MethodPoolB.h"
+}
diff --git a/test/Modules/method_pool.m b/test/Modules/method_pool.m
new file mode 100644 (file)
index 0000000..9574caa
--- /dev/null
@@ -0,0 +1,30 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodule-cache-path %t -fmodules -I %S/Inputs %s -verify
+
+@import MethodPoolA;
+
+
+// in other file: // expected-note{{using}}
+
+
+
+
+// in other file: expected-note{{also found}}
+
+void testMethod1(id object) {
+  [object method1]; 
+}
+
+void testMethod2(id object) {
+  [object method2:1];
+} 
+
+@import MethodPoolB;
+
+void testMethod1Again(id object) {
+  [object method1];
+}
+
+void testMethod2Again(id object) {
+  [object method2:1]; // expected-warning{{multiple methods named 'method2:' found}}
+}