summaryrefslogtreecommitdiffstats
path: root/clang/tools/CIndex/CIndexUSRs.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-03-19 20:39:03 +0000
committerTed Kremenek <kremenek@apple.com>2010-03-19 20:39:03 +0000
commite184ac5a660c800d960c7a19935a64103ba276f0 (patch)
tree96da5ea0ec9def23455486941bff313af061b52b /clang/tools/CIndex/CIndexUSRs.cpp
parentcf0843ed93d7b83c97e3e5b20ee06c638e138bb6 (diff)
downloadbcm5719-llvm-e184ac5a660c800d960c7a19935a64103ba276f0.tar.gz
bcm5719-llvm-e184ac5a660c800d960c7a19935a64103ba276f0.zip
Make the CIndex API more resilient to being used on invalid code.
llvm-svn: 98981
Diffstat (limited to 'clang/tools/CIndex/CIndexUSRs.cpp')
-rw-r--r--clang/tools/CIndex/CIndexUSRs.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/clang/tools/CIndex/CIndexUSRs.cpp b/clang/tools/CIndex/CIndexUSRs.cpp
index 9dbbd3541e4..8521971a306 100644
--- a/clang/tools/CIndex/CIndexUSRs.cpp
+++ b/clang/tools/CIndex/CIndexUSRs.cpp
@@ -155,14 +155,30 @@ void USRGenerator::VisitObjCContainerDecl(ObjCContainerDecl *D) {
break;
case Decl::ObjCCategory: {
ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D);
- GenObjCCategory(CD->getClassInterface()->getName(),
- CD->getName());
+ ObjCInterfaceDecl *ID = CD->getClassInterface();
+ if (!ID) {
+ // Handle invalid code where the @interface might not
+ // have been specified.
+ // FIXME: We should be able to generate this USR even if the
+ // @interface isn't available.
+ IgnoreResults = true;
+ return;
+ }
+ GenObjCCategory(ID->getName(), CD->getName());
break;
}
case Decl::ObjCCategoryImpl: {
ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D);
- GenObjCCategory(CD->getClassInterface()->getName(),
- CD->getName());
+ ObjCInterfaceDecl *ID = CD->getClassInterface();
+ if (!ID) {
+ // Handle invalid code where the @interface might not
+ // have been specified.
+ // FIXME: We should be able to generate this USR even if the
+ // @interface isn't available.
+ IgnoreResults = true;
+ return;
+ }
+ GenObjCCategory(ID->getName(), CD->getName());
break;
}
case Decl::ObjCProtocol:
@@ -251,7 +267,7 @@ CXString clang_getCursorUSR(CXCursor C) {
SUG->Visit(static_cast<Decl*>(D));
if (SUG->ignoreResults() || SUG.str().empty())
- return createCXString(NULL);
+ return createCXString("");
// Return a copy of the string that must be disposed by the caller.
return createCXString(SUG.str(), true);
OpenPOWER on IntegriCloud