diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-02-05 01:10:26 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-02-05 01:10:26 +0000 |
commit | 359c4a13691ad3b3ebd9381a467f9cb85a9faeb9 (patch) | |
tree | cc1458bc668259495c1627ab89f96b3839176cc2 /clang/tools/libclang/CIndexUSRs.cpp | |
parent | 4ee89902786e2bb5e0c964b83c889b5c4571d0c0 (diff) | |
download | bcm5719-llvm-359c4a13691ad3b3ebd9381a467f9cb85a9faeb9.tar.gz bcm5719-llvm-359c4a13691ad3b3ebd9381a467f9cb85a9faeb9.zip |
Don't crash when generating USRs for ObjC methods in protocols.
llvm-svn: 124920
Diffstat (limited to 'clang/tools/libclang/CIndexUSRs.cpp')
-rw-r--r-- | clang/tools/libclang/CIndexUSRs.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/clang/tools/libclang/CIndexUSRs.cpp b/clang/tools/libclang/CIndexUSRs.cpp index 36b91cf9786..6843f924c7d 100644 --- a/clang/tools/libclang/CIndexUSRs.cpp +++ b/clang/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(). |