From e28e95684407dd9c02a7f2252c7020d4a433ddae Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 9 Mar 2016 02:12:46 +0000 Subject: [PATCH] [index] libclang: Make sure to treat forward ObjC protocols as ObjCProtocolRef declarations, and fix related crash. rdar://25035376 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262985 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Index/IndexDecl.cpp | 8 ++++---- test/Index/index-refs.m | 5 +++++ tools/libclang/CXIndexDataConsumer.cpp | 8 ++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/Index/IndexDecl.cpp b/lib/Index/IndexDecl.cpp index af438f3684..5f5c49a2e3 100644 --- a/lib/Index/IndexDecl.cpp +++ b/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/test/Index/index-refs.m b/test/Index/index-refs.m index f25013b882..457712bcbc 100644 --- a/test/Index/index-refs.m +++ b/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: : kind: forward-ref diff --git a/tools/libclang/CXIndexDataConsumer.cpp b/tools/libclang/CXIndexDataConsumer.cpp index 322725ec65..4f89e43fd7 100644 --- a/tools/libclang/CXIndexDataConsumer.cpp +++ b/tools/libclang/CXIndexDataConsumer.cpp @@ -171,6 +171,14 @@ bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D, return true; } } + if (auto *ObjCPD = dyn_cast_or_null(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) { -- 2.40.0