]> granicus.if.org Git - clang/commitdiff
[libclang] Make sure we don't try to handle a CXCursor_NoDeclFound
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 9 Dec 2011 00:17:49 +0000 (00:17 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 9 Dec 2011 00:17:49 +0000 (00:17 +0000)
passed to clang_findReferencesInFile.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146211 91177308-0d34-0410-b5e6-96231b3b80d8

tools/libclang/CIndexHigh.cpp
tools/libclang/CXCursor.cpp

index bbb6d6dcadbd87654f6f92bcf0b3877333939410..4eabefb9259c29d5bb33df6f6a21fa4bc8e06240 100644 (file)
@@ -344,6 +344,11 @@ void clang_findReferencesInFile(CXCursor cursor, CXFile file,
       llvm::errs() << "clang_findReferencesInFile: Null cursor\n";
     return;
   }
+  if (cursor.kind == CXCursor_NoDeclFound) {
+    if (Logging)
+      llvm::errs() << "clang_findReferencesInFile: Got CXCursor_NoDeclFound\n";
+    return;
+  }
   if (!file) {
     if (Logging)
       llvm::errs() << "clang_findReferencesInFile: Null file\n";
index b4b9ed9d300387bb5c7d34e29d4fd0deb5998f14..5117a4d2b3e6ae81c1db121754174fc5ee0339f2 100644 (file)
@@ -746,8 +746,10 @@ ASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
 }
 
 ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) {
-  return static_cast<ASTUnit *>(static_cast<CXTranslationUnit>(Cursor.data[2])
-                                  ->TUData);
+  CXTranslationUnit TU = static_cast<CXTranslationUnit>(Cursor.data[2]);
+  if (!TU)
+    return 0;
+  return static_cast<ASTUnit *>(TU->TUData);
 }
 
 CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) {