aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-12-08 01:56:07 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-12-08 01:56:07 +0000
commite368a641a03617983dabb1e092d880e1089f576a (patch)
tree1370858318ec01f7182d329255e0cac5b9f48eaf
parent4ce83eba01c582fa4cbed25f74aaa2c5bf7d4fde (diff)
[libclang] When doing clang_findReferencesInFile, make sure we don't crash
if we come up against a null Decl. No test case unfortunately. rdar://10457799. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146127 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--tools/libclang/CIndexHigh.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/tools/libclang/CIndexHigh.cpp b/tools/libclang/CIndexHigh.cpp
index a4f85b4c12..bbb6d6dcad 100644
--- a/tools/libclang/CIndexHigh.cpp
+++ b/tools/libclang/CIndexHigh.cpp
@@ -73,17 +73,26 @@ struct FindFileIdRefVisitData {
/// we consider the canonical decl of the constructor decl to be the class
/// itself, so both 'C' can be highlighted.
Decl *getCanonical(Decl *D) const {
+ if (!D)
+ return 0;
+
D = D->getCanonicalDecl();
- if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D))
- return getCanonical(ImplD->getClassInterface());
- if (CXXConstructorDecl *CXXCtorD = dyn_cast<CXXConstructorDecl>(D))
+ if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) {
+ if (ImplD->getClassInterface())
+ return getCanonical(ImplD->getClassInterface());
+
+ } else if (CXXConstructorDecl *CXXCtorD = dyn_cast<CXXConstructorDecl>(D)) {
return getCanonical(CXXCtorD->getParent());
+ }
return D;
}
bool isHit(Decl *D) const {
+ if (!D)
+ return false;
+
D = getCanonical(D);
if (D == Dcl)
return true;
@@ -203,6 +212,9 @@ static void findIdRefsInFile(CXTranslationUnit TU, CXCursor declCursor,
FileID FID = SM.translateFile(File);
Decl *Dcl = cxcursor::getCursorDecl(declCursor);
+ if (!Dcl)
+ return;
+
FindFileIdRefVisitData data(TU, FID, Dcl,
cxcursor::getSelectorIdentifierIndex(declCursor),
Visitor);