Author: akirtzidis Date: Tue Mar 8 20:12:46 2016 New Revision: 262985 URL: http://llvm.org/viewvc/llvm-project?rev=262985&view=rev Log: [index] libclang: Make sure to treat forward ObjC protocols as ObjCProtocolRef declarations, and fix related crash.
rdar://25035376 Modified: cfe/trunk/lib/Index/IndexDecl.cpp cfe/trunk/test/Index/index-refs.m cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp Modified: cfe/trunk/lib/Index/IndexDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=262985&r1=262984&r2=262985&view=diff ============================================================================== --- cfe/trunk/lib/Index/IndexDecl.cpp (original) +++ cfe/trunk/lib/Index/IndexDecl.cpp Tue Mar 8 20:12:46 2016 @@ -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; } Modified: cfe/trunk/test/Index/index-refs.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-refs.m?rev=262985&r1=262984&r2=262985&view=diff ============================================================================== --- cfe/trunk/test/Index/index-refs.m (original) +++ cfe/trunk/test/Index/index-refs.m Tue Mar 8 20:12:46 2016 @@ -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 Modified: cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp?rev=262985&r1=262984&r2=262985&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp (original) +++ cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp Tue Mar 8 20:12:46 2016 @@ -171,6 +171,14 @@ bool CXIndexDataConsumer::handleDeclOccu 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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits