[cfe-commits] r146127 - /cfe/trunk/tools/libclang/CIndexHigh.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Dec 7 17:56:08 PST 2011


Author: akirtzidis
Date: Wed Dec  7 19:56:07 2011
New Revision: 146127

URL: http://llvm.org/viewvc/llvm-project?rev=146127&view=rev
Log:
[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.

Modified:
    cfe/trunk/tools/libclang/CIndexHigh.cpp

Modified: cfe/trunk/tools/libclang/CIndexHigh.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexHigh.cpp?rev=146127&r1=146126&r2=146127&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexHigh.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexHigh.cpp Wed Dec  7 19:56:07 2011
@@ -73,17 +73,26 @@
   /// 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 @@
 
   FileID FID = SM.translateFile(File);
   Decl *Dcl = cxcursor::getCursorDecl(declCursor);
+  if (!Dcl)
+    return;
+
   FindFileIdRefVisitData data(TU, FID, Dcl,
                               cxcursor::getSelectorIdentifierIndex(declCursor),
                               Visitor);





More information about the cfe-commits mailing list