aboutsummaryrefslogtreecommitdiff
path: root/tools/libclang/CIndexUSRs.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-02-05 01:10:26 +0000
committerTed Kremenek <kremenek@apple.com>2011-02-05 01:10:26 +0000
commit52d6bbe3aa1e70d40c7cc892a12f41b6017f5c6c (patch)
treebe81593d0135e06fcde7139d6a0ff013854f2348 /tools/libclang/CIndexUSRs.cpp
parent1e99a7726ac0d4870f27d1e8425b6ca8833933e4 (diff)
Don't crash when generating USRs for ObjC methods in protocols.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124920 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/libclang/CIndexUSRs.cpp')
-rw-r--r--tools/libclang/CIndexUSRs.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/tools/libclang/CIndexUSRs.cpp b/tools/libclang/CIndexUSRs.cpp
index 36b91cf978..6843f924c7 100644
--- a/tools/libclang/CIndexUSRs.cpp
+++ b/tools/libclang/CIndexUSRs.cpp
@@ -283,15 +283,20 @@ void USRGenerator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
}
void USRGenerator::VisitObjCMethodDecl(ObjCMethodDecl *D) {
- // The USR for a method declared in a class extension or category is based on
- // the ObjCInterfaceDecl, not the ObjCCategoryDecl.
- ObjCInterfaceDecl *ID = D->getClassInterface();
- if (!ID) {
- IgnoreResults = true;
- return;
+ DeclContext *container = D->getDeclContext();
+ if (ObjCProtocolDecl *pd = dyn_cast<ObjCProtocolDecl>(container)) {
+ Visit(pd);
+ }
+ else {
+ // The USR for a method declared in a class extension or category is based on
+ // the ObjCInterfaceDecl, not the ObjCCategoryDecl.
+ ObjCInterfaceDecl *ID = D->getClassInterface();
+ if (!ID) {
+ IgnoreResults = true;
+ return;
+ }
+ Visit(ID);
}
- Visit(ID);
-
// Ideally we would use 'GenObjCMethod', but this is such a hot path
// for Objective-C code that we don't want to use
// DeclarationName::getAsString().