From 453b012513e67aa99b3d4c5f7712231012efeca3 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 12 Nov 2010 07:15:47 +0000 Subject: Make sure to always check the result of SourceManager::getPresumedLoc(), so that we don't try to make use of an invalid presumed location. Doing so can cause crashes. llvm-svn: 118885 --- clang/lib/Frontend/DocumentXML.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'clang/lib/Frontend/DocumentXML.cpp') diff --git a/clang/lib/Frontend/DocumentXML.cpp b/clang/lib/Frontend/DocumentXML.cpp index 2f7e995b208..b24ece5119d 100644 --- a/clang/lib/Frontend/DocumentXML.cpp +++ b/clang/lib/Frontend/DocumentXML.cpp @@ -327,9 +327,11 @@ PresumedLoc DocumentXML::addLocation(const SourceLocation& Loc) if (!SpellingLoc.isInvalid()) { PLoc = SM.getPresumedLoc(SpellingLoc); - addSourceFileAttribute(PLoc.getFilename()); - addAttribute("line", PLoc.getLine()); - addAttribute("col", PLoc.getColumn()); + if (PLoc.isValid()) { + addSourceFileAttribute(PLoc.getFilename()); + addAttribute("line", PLoc.getLine()); + addAttribute("col", PLoc.getColumn()); + } } // else there is no error in some cases (eg. CXXThisExpr) return PLoc; @@ -346,8 +348,9 @@ void DocumentXML::addLocationRange(const SourceRange& R) if (!SpellingLoc.isInvalid()) { PresumedLoc PLoc = SM.getPresumedLoc(SpellingLoc); - if (PStartLoc.isInvalid() || - strcmp(PLoc.getFilename(), PStartLoc.getFilename()) != 0) { + if (PLoc.isInvalid()) { + } else if (PStartLoc.isInvalid() || + strcmp(PLoc.getFilename(), PStartLoc.getFilename()) != 0) { addToMap(SourceFiles, PLoc.getFilename(), ID_FILE); addAttribute("endfile", PLoc.getFilename()); addAttribute("endline", PLoc.getLine()); -- cgit v1.2.3