[cfe-commits] r94391 - in /cfe/trunk/tools/CIndex: CIndex.cpp CXCursor.cpp

Daniel Dunbar daniel at zuster.org
Sun Jan 24 16:40:30 PST 2010


Author: ddunbar
Date: Sun Jan 24 18:40:30 2010
New Revision: 94391

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

Modified:
    cfe/trunk/tools/CIndex/CIndex.cpp
    cfe/trunk/tools/CIndex/CXCursor.cpp

Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=94391&r1=94390&r2=94391&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Sun Jan 24 18:40:30 2010
@@ -783,7 +783,7 @@
 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;
   }
   

Modified: cfe/trunk/tools/CIndex/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CXCursor.cpp?rev=94391&r1=94390&r2=94391&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CXCursor.cpp (original)
+++ cfe/trunk/tools/CIndex/CXCursor.cpp Sun Jan 24 18:40:30 2010
@@ -29,6 +29,7 @@
 }
 
 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 @@
 }
 
 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::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, 
                                                SourceLocation Loc, 
                                                ASTUnit *TU) {
+  assert(Super && TU && "Invalid arguments!");
   void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
   CXCursor C = { CXCursor_ObjCSuperClassRef, { Super, RawLoc, TU } };
   return C;    
@@ -230,6 +234,7 @@
 CXCursor cxcursor::MakeCursorObjCProtocolRef(ObjCProtocolDecl *Super, 
                                              SourceLocation Loc, 
                                              ASTUnit *TU) {
+  assert(Super && TU && "Invalid arguments!");
   void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
   CXCursor C = { CXCursor_ObjCProtocolRef, { Super, RawLoc, TU } };
   return C;    
@@ -246,6 +251,7 @@
 CXCursor cxcursor::MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, 
                                           SourceLocation Loc, 
                                           ASTUnit *TU) {
+  assert(Class && TU && "Invalid arguments!");
   void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
   CXCursor C = { CXCursor_ObjCClassRef, { Class, RawLoc, TU } };
   return C;    
@@ -261,6 +267,7 @@
 
 CXCursor cxcursor::MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, 
                                      ASTUnit *TU) {
+  assert(Type && TU && "Invalid arguments!");
   void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
   CXCursor C = { CXCursor_TypeRef, { Type, RawLoc, TU } };
   return C;    





More information about the cfe-commits mailing list