diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-11-02 00:39:22 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-11-02 00:39:22 +0000 |
commit | c417fa024495c10a5e678ea36a5f8c715528bdd1 (patch) | |
tree | 54eca3610c043e6988e298c701433a5ef4336a7a | |
parent | 053105d58552c600a2e56473592212a9bddafcd4 (diff) |
Teach SourceManager::getPresumedLoc() how to fail gracefully if getLineNumber/getColumnNumber fail
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117990 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Basic/SourceManager.cpp | 10 | ||||
-rw-r--r-- | lib/Frontend/TextDiagnosticPrinter.cpp | 2 |
2 files changed, 9 insertions, 3 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 8564a76feb..7127e80018 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -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 diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index 1e453a08fd..9e450d25c3 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -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); |