aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/DocumentXML.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-11-12 07:15:47 +0000
committerDouglas Gregor <dgregor@apple.com>2010-11-12 07:15:47 +0000
commitcb7b1e17b63967317ab5cc55682168cf0380519a (patch)
treeae64d4fe18e56974c3aae2c99e86aa954410ccdb /lib/Frontend/DocumentXML.cpp
parent8f0889ce457db51d3af1eb1245bceee272d4dc7d (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118885 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/DocumentXML.cpp')
-rw-r--r--lib/Frontend/DocumentXML.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/Frontend/DocumentXML.cpp b/lib/Frontend/DocumentXML.cpp
index 2f7e995b20..b24ece5119 100644
--- a/lib/Frontend/DocumentXML.cpp
+++ b/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());