From: Daniel Dunbar Date: Tue, 2 Feb 2010 05:00:22 +0000 (+0000) Subject: CIndex: Fix a crash in clang_createTranslationUnitFromSourceFile when using X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c29f4c396019f51e09511e385d6c07c4ea2a1464;p=clang CIndex: Fix a crash in clang_createTranslationUnitFromSourceFile when using external ASTs, and the ASTUnit fails to load. Also, move getLocationFromExpr outside extern "C" block. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95065 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index 0bb862eb1a..920c5ec070 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -1094,9 +1094,11 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, 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 @@ static Decl *getDeclFromExpr(Stmt *E) { return 0; } +static SourceLocation getLocationFromExpr(Expr *E) { + if (ObjCMessageExpr *Msg = dyn_cast(E)) + return /*FIXME:*/Msg->getLeftLoc(); + if (DeclRefExpr *DRE = dyn_cast(E)) + return DRE->getLocation(); + if (MemberExpr *Member = dyn_cast(E)) + return Member->getMemberLoc(); + if (ObjCIvarRefExpr *Ivar = dyn_cast(E)) + return Ivar->getLocation(); + return E->getLocStart(); +} + extern "C" { unsigned clang_visitChildren(CXCursor parent, @@ -1504,18 +1518,6 @@ CXCursorKind clang_getCursorKind(CXCursor C) { return C.kind; } -static SourceLocation getLocationFromExpr(Expr *E) { - if (ObjCMessageExpr *Msg = dyn_cast(E)) - return /*FIXME:*/Msg->getLeftLoc(); - if (DeclRefExpr *DRE = dyn_cast(E)) - return DRE->getLocation(); - if (MemberExpr *Member = dyn_cast(E)) - return Member->getMemberLoc(); - if (ObjCIvarRefExpr *Ivar = dyn_cast(E)) - return Ivar->getLocation(); - return E->getLocStart(); -} - CXSourceLocation clang_getCursorLocation(CXCursor C) { if (clang_isReference(C.kind)) { switch (C.kind) {