Check for null ObjCInterfaceDecls returned from getClassInterface() when generating USRs. While I have no test case for this (could not create one), this shows up in crash reports. Tentatively fixes <rdar://problem/8452791>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114392 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndexUSRs.cpp b/tools/libclang/CIndexUSRs.cpp
index 5541657..4f23e59 100644
--- a/tools/libclang/CIndexUSRs.cpp
+++ b/tools/libclang/CIndexUSRs.cpp
@@ -286,10 +286,17 @@
do {
if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(container))
if (CD->IsClassExtension()) {
- Visit(CD->getClassInterface());
- break;
- }
- Visit(cast<Decl>(D->getDeclContext()));
+ // ID can be null with invalid code.
+ if (ObjCInterfaceDecl *ID = CD->getClassInterface()) {
+ Visit(ID);
+ break;
+ }
+ // Invalid code. Can't generate USR.
+ IgnoreResults = true;
+ return;
+ }
+
+ Visit(container);
}
while (false);