[cfe-commits] r95065 - /cfe/trunk/tools/CIndex/CIndex.cpp

Daniel Dunbar daniel at zuster.org
Mon Feb 1 21:00:27 PST 2010


Author: ddunbar
Date: Mon Feb  1 23:00:22 2010
New Revision: 95065

URL: http://llvm.org/viewvc/llvm-project?rev=95065&view=rev
Log:
CIndex: Fix a crash in clang_createTranslationUnitFromSourceFile when using
external ASTs, and the ASTUnit fails to load.

Also, move getLocationFromExpr outside extern "C" block.

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

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

==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Mon Feb  1 23:00:22 2010
@@ -1094,9 +1094,11 @@
   if (ATU)
     ATU->unlinkTemporaryFile();
   
-  ReportSerializedDiagnostics(DiagnosticsFile, *Diags, 
-                              num_unsaved_files, unsaved_files,
-                              ATU->getASTContext().getLangOptions());
+  // FIXME: Currently we don't report diagnostics on invalid ASTs.
+  if (ATU)
+    ReportSerializedDiagnostics(DiagnosticsFile, *Diags, 
+                                num_unsaved_files, unsaved_files,
+                                ATU->getASTContext().getLangOptions());
 
   for (unsigned i = 0, e = TemporaryFiles.size(); i != e; ++i)
     TemporaryFiles[i].eraseFromDisk();
@@ -1306,6 +1308,18 @@
   return 0;
 }
 
+static SourceLocation getLocationFromExpr(Expr *E) {
+  if (ObjCMessageExpr *Msg = dyn_cast<ObjCMessageExpr>(E))
+    return /*FIXME:*/Msg->getLeftLoc();
+  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
+    return DRE->getLocation();
+  if (MemberExpr *Member = dyn_cast<MemberExpr>(E))
+    return Member->getMemberLoc();
+  if (ObjCIvarRefExpr *Ivar = dyn_cast<ObjCIvarRefExpr>(E))
+    return Ivar->getLocation();
+  return E->getLocStart();
+}
+
 extern "C" {
   
 unsigned clang_visitChildren(CXCursor parent, 
@@ -1504,18 +1518,6 @@
   return C.kind;
 }
 
-static SourceLocation getLocationFromExpr(Expr *E) {
-  if (ObjCMessageExpr *Msg = dyn_cast<ObjCMessageExpr>(E))
-    return /*FIXME:*/Msg->getLeftLoc();
-  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
-    return DRE->getLocation();
-  if (MemberExpr *Member = dyn_cast<MemberExpr>(E))
-    return Member->getMemberLoc();
-  if (ObjCIvarRefExpr *Ivar = dyn_cast<ObjCIvarRefExpr>(E))
-    return Ivar->getLocation();
-  return E->getLocStart();
-}
-
 CXSourceLocation clang_getCursorLocation(CXCursor C) {
   if (clang_isReference(C.kind)) {
     switch (C.kind) {





More information about the cfe-commits mailing list