aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/TextDiagnosticPrinter.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-12-04 07:06:35 +0000
committerChris Lattner <sabre@nondot.org>2009-12-04 07:06:35 +0000
commit2e77aa1c2a596b66d436d27b8ec2ea695cf9a748 (patch)
treed0359e5524ee44d70eaf735b41de91880adb4ba3 /lib/Frontend/TextDiagnosticPrinter.cpp
parentbfb4fc9ebc64ec3db597441d4b79adcd0f69cf58 (diff)
Use PresumedLoc when emitting the 'included from' diagnostics. For a malformed
test like this: #line 4 "foo" #define XX ? #if XX #endif We now emit: In file included from t.c:7: foo:7:5: error: invalid token at start of a preprocessor expression #if XX ^ foo:5:12: note: instantiated from: #define XX ? ^ instead of: In file included from t.c:7: foo:7:5: error: invalid token at start of a preprocessor expression #if XX ^ ./t.h:6:12: note: instantiated from: #define XX ? ^ (where the note doesn't obey #line or print the include stack when needed). This fixes PR5617 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90554 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/TextDiagnosticPrinter.cpp')
-rw-r--r--lib/Frontend/TextDiagnosticPrinter.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp
index 6ab0e16052..52a0f48363 100644
--- a/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -279,13 +279,14 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
assert(!Loc.isInvalid() && "must have a valid source location here");
// If this is a macro ID, first emit information about where this was
- // instantiated (recursively) then emit information about where. the token was
+ // instantiated (recursively) then emit information about where the token was
// spelled from.
if (!Loc.isFileID()) {
SourceLocation OneLevelUp = SM.getImmediateInstantiationRange(Loc).first;
// FIXME: Map ranges?
EmitCaretDiagnostic(OneLevelUp, Ranges, NumRanges, SM, 0, 0, Columns);
+ // Map the location.
Loc = SM.getImmediateSpellingLoc(Loc);
// Map the ranges.
@@ -295,15 +296,22 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
if (E.isMacroID()) E = SM.getImmediateSpellingLoc(E);
Ranges[i] = SourceRange(S, E);
}
+
+ // Get the pretty name, according to #line directives etc.
+ PresumedLoc PLoc = SM.getPresumedLoc(Loc);
+
+ // If this diagnostic is not in the main file, print out the "included from"
+ // lines.
+ if (LastWarningLoc != PLoc.getIncludeLoc()) {
+ LastWarningLoc = PLoc.getIncludeLoc();
+ PrintIncludeStack(LastWarningLoc, SM);
+ }
if (DiagOpts->ShowLocation) {
- std::pair<FileID, unsigned> IInfo = SM.getDecomposedInstantiationLoc(Loc);
-
// Emit the file/line/column that this expansion came from.
- OS << SM.getBuffer(IInfo.first)->getBufferIdentifier() << ':'
- << SM.getLineNumber(IInfo.first, IInfo.second) << ':';
+ OS << PLoc.getFilename() << ':' << PLoc.getLine() << ':';
if (DiagOpts->ShowColumn)
- OS << SM.getColumnNumber(IInfo.first, IInfo.second) << ':';
+ OS << PLoc.getColumn() << ':';
OS << ' ';
}
OS << "note: instantiated from:\n";