Harden Clang's cursor visitation logic against NULL declaration,

statement, and expression pointers. While these shouldn't happen, it's
better to be safe in libclang.

llvm-svn: 129539
This commit is contained in:
Douglas Gregor 2011-04-14 21:41:34 +00:00
parent 92651ec374
commit 7df2126000
1 changed files with 16 additions and 5 deletions

View File

@ -494,14 +494,25 @@ bool CursorVisitor::VisitChildren(CXCursor Cursor) {
if (clang_isDeclaration(Cursor.kind)) { if (clang_isDeclaration(Cursor.kind)) {
Decl *D = getCursorDecl(Cursor); Decl *D = getCursorDecl(Cursor);
assert(D && "Invalid declaration cursor"); if (!D)
return false;
return VisitAttributes(D) || Visit(D); return VisitAttributes(D) || Visit(D);
} }
if (clang_isStatement(Cursor.kind)) if (clang_isStatement(Cursor.kind)) {
return Visit(getCursorStmt(Cursor)); if (Stmt *S = getCursorStmt(Cursor))
if (clang_isExpression(Cursor.kind)) return Visit(S);
return Visit(getCursorExpr(Cursor));
return false;
}
if (clang_isExpression(Cursor.kind)) {
if (Expr *E = getCursorExpr(Cursor))
return Visit(E);
return false;
}
if (clang_isTranslationUnit(Cursor.kind)) { if (clang_isTranslationUnit(Cursor.kind)) {
CXTranslationUnit tu = getCursorTU(Cursor); CXTranslationUnit tu = getCursorTU(Cursor);