From 359c4a13691ad3b3ebd9381a467f9cb85a9faeb9 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sat, 5 Feb 2011 01:10:26 +0000 Subject: Don't crash when generating USRs for ObjC methods in protocols. llvm-svn: 124920 --- clang/tools/libclang/CIndexUSRs.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'clang/tools/libclang/CIndexUSRs.cpp') 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(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(). -- cgit v1.2.3