[libclang] Make sure we don't try to handle a CXCursor_NoDeclFound
passed to clang_findReferencesInFile.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146211 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndexHigh.cpp b/tools/libclang/CIndexHigh.cpp
index bbb6d6d..4eabefb 100644
--- a/tools/libclang/CIndexHigh.cpp
+++ b/tools/libclang/CIndexHigh.cpp
@@ -344,6 +344,11 @@
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";
diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp
index b4b9ed9..5117a4d 100644
--- a/tools/libclang/CXCursor.cpp
+++ b/tools/libclang/CXCursor.cpp
@@ -746,8 +746,10 @@
}
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) {