Teach SourceManager::getPresumedLoc() how to fail gracefully if getLineNumber/getColu...
authorDouglas Gregor <dgregor@apple.com>
Tue, 2 Nov 2010 00:39:22 +0000 (00:39 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 2 Nov 2010 00:39:22 +0000 (00:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117990 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/SourceManager.cpp
lib/Frontend/TextDiagnosticPrinter.cpp

index 8564a76feb1b30779866384366c6321f0262a500..7127e80018655b005f3771bbe661f910f5652037 100644 (file)
@@ -1058,8 +1058,14 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc) const {
     Filename = C->Entry->getName();
   else
     Filename = C->getBuffer(Diag, *this)->getBufferIdentifier();
-  unsigned LineNo = getLineNumber(LocInfo.first, LocInfo.second);
-  unsigned ColNo  = getColumnNumber(LocInfo.first, LocInfo.second);
+  bool Invalid = false;
+  unsigned LineNo = getLineNumber(LocInfo.first, LocInfo.second, &Invalid);
+  if (Invalid)
+    return PresumedLoc();
+  unsigned ColNo  = getColumnNumber(LocInfo.first, LocInfo.second, &Invalid);
+  if (Invalid)
+    return PresumedLoc();
+  
   SourceLocation IncludeLoc = FI.getIncludeLoc();
 
   // If we have #line directives in this file, update and overwrite the physical
index 1e453a08fdb99c44438fd29d898f44c3014a4a78..9e450d25c3d17fe71cda4a6e3930fe60ae605368 100644 (file)
@@ -781,7 +781,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
     }
 
     // Compute the column number.
-    if (DiagOpts->ShowLocation) {
+    if (DiagOpts->ShowLocation && PLoc.isValid()) {
       if (DiagOpts->ShowColors)
         OS.changeColor(savedColor, true);