From 54d67caeee4fdce81f07163832f1163d5f2af5d2 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 25 Jan 2010 00:40:30 +0000 Subject: [PATCH] CIndex: Don't crash when visitor passes null child statements, and sprinkle some asserts in cursor construction functions to make this more obvious. Doug, please check. c-index-test would previously crash on this code: -- for(;;) {} -- Do we need a custom visit of the for statement to cover the variable declarations? git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94391 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/CIndex/CIndex.cpp | 2 +- tools/CIndex/CXCursor.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index 84f908d571..4436709f80 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -783,7 +783,7 @@ bool CursorVisitor::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { bool CursorVisitor::VisitStmt(Stmt *S) { for (Stmt::child_iterator Child = S->child_begin(), ChildEnd = S->child_end(); Child != ChildEnd; ++Child) { - if (Visit(MakeCXCursor(*Child, StmtParent, TU))) + if (*Child && Visit(MakeCXCursor(*Child, StmtParent, TU))) return true; } diff --git a/tools/CIndex/CXCursor.cpp b/tools/CIndex/CXCursor.cpp index 63d9bc9f2e..64ff493946 100644 --- a/tools/CIndex/CXCursor.cpp +++ b/tools/CIndex/CXCursor.cpp @@ -29,6 +29,7 @@ CXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K) { } static CXCursorKind GetCursorKind(Decl *D) { + assert(D && "Invalid arguments!"); switch (D->getKind()) { case Decl::Enum: return CXCursor_EnumDecl; case Decl::EnumConstant: return CXCursor_EnumConstantDecl; @@ -72,11 +73,13 @@ static CXCursorKind GetCursorKind(Decl *D) { } CXCursor cxcursor::MakeCXCursor(Decl *D, ASTUnit *TU) { + assert(D && TU && "Invalid arguments!"); CXCursor C = { GetCursorKind(D), { D, 0, TU } }; return C; } CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, ASTUnit *TU) { + assert(S && TU && "Invalid arguments!"); CXCursorKind K = CXCursor_NotImplemented; switch (S->getStmtClass()) { @@ -214,6 +217,7 @@ CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, ASTUnit *TU) { CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, SourceLocation Loc, ASTUnit *TU) { + assert(Super && TU && "Invalid arguments!"); void *RawLoc = reinterpret_cast(Loc.getRawEncoding()); CXCursor C = { CXCursor_ObjCSuperClassRef, { Super, RawLoc, TU } }; return C; @@ -230,6 +234,7 @@ cxcursor::getCursorObjCSuperClassRef(CXCursor C) { CXCursor cxcursor::MakeCursorObjCProtocolRef(ObjCProtocolDecl *Super, SourceLocation Loc, ASTUnit *TU) { + assert(Super && TU && "Invalid arguments!"); void *RawLoc = reinterpret_cast(Loc.getRawEncoding()); CXCursor C = { CXCursor_ObjCProtocolRef, { Super, RawLoc, TU } }; return C; @@ -246,6 +251,7 @@ cxcursor::getCursorObjCProtocolRef(CXCursor C) { CXCursor cxcursor::MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc, ASTUnit *TU) { + assert(Class && TU && "Invalid arguments!"); void *RawLoc = reinterpret_cast(Loc.getRawEncoding()); CXCursor C = { CXCursor_ObjCClassRef, { Class, RawLoc, TU } }; return C; @@ -261,6 +267,7 @@ cxcursor::getCursorObjCClassRef(CXCursor C) { CXCursor cxcursor::MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU) { + assert(Type && TU && "Invalid arguments!"); void *RawLoc = reinterpret_cast(Loc.getRawEncoding()); CXCursor C = { CXCursor_TypeRef, { Type, RawLoc, TU } }; return C; -- 2.50.1