diff options
| -rw-r--r-- | clang/lib/Index/IndexDecl.cpp | 8 | ||||
| -rw-r--r-- | clang/test/Index/index-refs.m | 5 | ||||
| -rw-r--r-- | clang/tools/libclang/CXIndexDataConsumer.cpp | 8 |
3 files changed, 17 insertions, 4 deletions
diff --git a/clang/lib/Index/IndexDecl.cpp b/clang/lib/Index/IndexDecl.cpp index af438f36843..5f5c49a2e33 100644 --- a/clang/lib/Index/IndexDecl.cpp +++ b/clang/lib/Index/IndexDecl.cpp @@ -227,8 +227,8 @@ public: TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D)); TRY_TO(IndexCtx.indexDeclContext(D)); } else { - return IndexCtx.handleReference(D, D->getLocation(), nullptr, nullptr, - SymbolRoleSet()); + return IndexCtx.handleReference(D, D->getLocation(), nullptr, + D->getDeclContext(), SymbolRoleSet()); } return true; } @@ -239,8 +239,8 @@ public: TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D)); TRY_TO(IndexCtx.indexDeclContext(D)); } else { - return IndexCtx.handleReference(D, D->getLocation(), nullptr, nullptr, - SymbolRoleSet()); + return IndexCtx.handleReference(D, D->getLocation(), nullptr, + D->getDeclContext(), SymbolRoleSet()); } return true; } diff --git a/clang/test/Index/index-refs.m b/clang/test/Index/index-refs.m index f25013b882f..457712bcbc7 100644 --- a/clang/test/Index/index-refs.m +++ b/clang/test/Index/index-refs.m @@ -21,7 +21,12 @@ void foo2() { [I clsMeth]; } +@protocol ForwardProt; + // RUN: c-index-test -index-file %s | FileCheck %s // CHECK: [indexEntityReference]: kind: objc-protocol | name: Prot | {{.*}} | loc: 12:27 // CHECK: [indexEntityReference]: kind: struct | name: FooS | {{.*}} | loc: 13:18 // CHECK: [indexEntityReference]: kind: objc-class | name: I | {{.*}} | loc: 21:4 + +// CHECK: [indexDeclaration]: kind: objc-protocol | name: ForwardProt | {{.*}} | loc: 24:11 +// CHECK-NEXT: <ObjCContainerInfo>: kind: forward-ref diff --git a/clang/tools/libclang/CXIndexDataConsumer.cpp b/clang/tools/libclang/CXIndexDataConsumer.cpp index 322725ec654..4f89e43fd7b 100644 --- a/clang/tools/libclang/CXIndexDataConsumer.cpp +++ b/clang/tools/libclang/CXIndexDataConsumer.cpp @@ -171,6 +171,14 @@ bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D, return true; } } + if (auto *ObjCPD = dyn_cast_or_null<ObjCProtocolDecl>(ASTNode.OrigD)) { + if (!ObjCPD->isThisDeclarationADefinition() && + ObjCPD->getLocation() == Loc) { + // The libclang API treats this as ObjCProtocolRef declaration. + IndexingDeclVisitor(*this, Loc, nullptr).Visit(ObjCPD); + return true; + } + } CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct; if (Roles & (unsigned)SymbolRole::Implicit) { |

