bnbarham created this revision.
bnbarham added a reviewer: akyrtzi.
Herald added subscribers: cfe-commits, arphaman, dexonsmith.
Herald added a project: clang.
bnbarham requested review of this revision.

ObjCContainerDecl.getMethod returns a nullptr by default when the
container is a hidden prototype. Callsites where the method is being
looked up on the redeclaration's own container should skip this check
since they (rightly) expect a valid method to be found.

Resolves rdar://69444243


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89024

Files:
  clang/lib/AST/DeclObjC.cpp
  clang/test/Index/Inputs/hidden-redecls-sub.h
  clang/test/Index/Inputs/hidden-redecls.h
  clang/test/Index/Inputs/module.map
  clang/test/Index/hidden-redecls.m


Index: clang/test/Index/hidden-redecls.m
===================================================================
--- /dev/null
+++ clang/test/Index/hidden-redecls.m
@@ -0,0 +1,12 @@
+@import hidden_redecls;
+
+@interface Foo (Top)
+- (void)top_method;
+@end
+
+// p1_method in protocol P1 is hidden since module_redecls.sub hasn't been
+// imported yet. Check it is still indexed.
+
+// RUN: c-index-test -index-file-full %s -isystem %S/Inputs -fmodules | 
FileCheck %s
+// CHECK: [indexDeclaration]: kind: objc-instance-method | name: p1_method | 
{{.*}} | loc: {{.*}}/hidden-redecls-sub.h:2:9 | {{.*}} | isRedecl: 0
+// CHECK: [indexDeclaration]: kind: objc-instance-method | name: p1_method | 
{{.*}} | loc: {{.*}}/hidden-redecls-sub.h:3:9 | {{.*}} | isRedecl: 1
Index: clang/test/Index/Inputs/module.map
===================================================================
--- clang/test/Index/Inputs/module.map
+++ clang/test/Index/Inputs/module.map
@@ -20,3 +20,11 @@
     export *
   }
 }
+
+module hidden_redecls {
+  header "hidden-redecls.h"
+
+  explicit module sub {
+    header "hidden-redecls-sub.h"
+  }
+}
Index: clang/test/Index/Inputs/hidden-redecls.h
===================================================================
--- /dev/null
+++ clang/test/Index/Inputs/hidden-redecls.h
@@ -0,0 +1,3 @@
+@interface Foo
+- (void)parent_method;
+@end
Index: clang/test/Index/Inputs/hidden-redecls-sub.h
===================================================================
--- /dev/null
+++ clang/test/Index/Inputs/hidden-redecls-sub.h
@@ -0,0 +1,7 @@
+@protocol P1
+- (void)p1_method;
+- (void)p1_method;
+@end
+
+@interface Foo (SubP1) <P1>
+@end
Index: clang/lib/AST/DeclObjC.cpp
===================================================================
--- clang/lib/AST/DeclObjC.cpp
+++ clang/lib/AST/DeclObjC.cpp
@@ -950,7 +950,8 @@
   if (!Redecl && isRedeclaration()) {
     // This is the last redeclaration, go back to the first method.
     return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
-                                                    isInstanceMethod());
+                                                    isInstanceMethod(),
+                                                    /*AllowHidden=*/true);
   }
 
   return Redecl ? Redecl : this;
@@ -983,7 +984,8 @@
   if (isRedeclaration()) {
     // It is possible that we have not done deserializing the ObjCMethod yet.
     ObjCMethodDecl *MD =
-        cast<ObjCContainerDecl>(CtxD)->getMethod(Sel, isInstanceMethod());
+      cast<ObjCContainerDecl>(CtxD)->getMethod(Sel, isInstanceMethod(),
+                                               /*AllowHidden=*/true);
     return MD ? MD : this;
   }
 
@@ -1308,8 +1310,9 @@
   const ObjCMethodDecl *Method = this;
 
   if (Method->isRedeclaration()) {
-    Method = cast<ObjCContainerDecl>(Method->getDeclContext())->
-                   getMethod(Method->getSelector(), 
Method->isInstanceMethod());
+    Method = cast<ObjCContainerDecl>(Method->getDeclContext())
+                 ->getMethod(Method->getSelector(), Method->isInstanceMethod(),
+                             /*AllowHidden=*/true);
   }
 
   if (Method->isOverriding()) {


Index: clang/test/Index/hidden-redecls.m
===================================================================
--- /dev/null
+++ clang/test/Index/hidden-redecls.m
@@ -0,0 +1,12 @@
+@import hidden_redecls;
+
+@interface Foo (Top)
+- (void)top_method;
+@end
+
+// p1_method in protocol P1 is hidden since module_redecls.sub hasn't been
+// imported yet. Check it is still indexed.
+
+// RUN: c-index-test -index-file-full %s -isystem %S/Inputs -fmodules | FileCheck %s
+// CHECK: [indexDeclaration]: kind: objc-instance-method | name: p1_method | {{.*}} | loc: {{.*}}/hidden-redecls-sub.h:2:9 | {{.*}} | isRedecl: 0
+// CHECK: [indexDeclaration]: kind: objc-instance-method | name: p1_method | {{.*}} | loc: {{.*}}/hidden-redecls-sub.h:3:9 | {{.*}} | isRedecl: 1
Index: clang/test/Index/Inputs/module.map
===================================================================
--- clang/test/Index/Inputs/module.map
+++ clang/test/Index/Inputs/module.map
@@ -20,3 +20,11 @@
     export *
   }
 }
+
+module hidden_redecls {
+  header "hidden-redecls.h"
+
+  explicit module sub {
+    header "hidden-redecls-sub.h"
+  }
+}
Index: clang/test/Index/Inputs/hidden-redecls.h
===================================================================
--- /dev/null
+++ clang/test/Index/Inputs/hidden-redecls.h
@@ -0,0 +1,3 @@
+@interface Foo
+- (void)parent_method;
+@end
Index: clang/test/Index/Inputs/hidden-redecls-sub.h
===================================================================
--- /dev/null
+++ clang/test/Index/Inputs/hidden-redecls-sub.h
@@ -0,0 +1,7 @@
+@protocol P1
+- (void)p1_method;
+- (void)p1_method;
+@end
+
+@interface Foo (SubP1) <P1>
+@end
Index: clang/lib/AST/DeclObjC.cpp
===================================================================
--- clang/lib/AST/DeclObjC.cpp
+++ clang/lib/AST/DeclObjC.cpp
@@ -950,7 +950,8 @@
   if (!Redecl && isRedeclaration()) {
     // This is the last redeclaration, go back to the first method.
     return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
-                                                    isInstanceMethod());
+                                                    isInstanceMethod(),
+                                                    /*AllowHidden=*/true);
   }
 
   return Redecl ? Redecl : this;
@@ -983,7 +984,8 @@
   if (isRedeclaration()) {
     // It is possible that we have not done deserializing the ObjCMethod yet.
     ObjCMethodDecl *MD =
-        cast<ObjCContainerDecl>(CtxD)->getMethod(Sel, isInstanceMethod());
+      cast<ObjCContainerDecl>(CtxD)->getMethod(Sel, isInstanceMethod(),
+                                               /*AllowHidden=*/true);
     return MD ? MD : this;
   }
 
@@ -1308,8 +1310,9 @@
   const ObjCMethodDecl *Method = this;
 
   if (Method->isRedeclaration()) {
-    Method = cast<ObjCContainerDecl>(Method->getDeclContext())->
-                   getMethod(Method->getSelector(), Method->isInstanceMethod());
+    Method = cast<ObjCContainerDecl>(Method->getDeclContext())
+                 ->getMethod(Method->getSelector(), Method->isInstanceMethod(),
+                             /*AllowHidden=*/true);
   }
 
   if (Method->isOverriding()) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to