aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-12 06:43:35 +0000
committerChris Lattner <sabre@nondot.org>2008-01-12 06:43:35 +0000
commite41b7cd768fe5722c1adcf4056d586c59514ec29 (patch)
tree93e638a3adb2bf33e3ec9418738572435f9eee0a
parent3d2da3d765123e15290c38ba44f4434462bb88d5 (diff)
When forming the squigly underline for a diagnostic, make sure to
verify that the source range corresponds to the current file, not just the current line. This allows us to emit: a.c:1:44: error: invalid operands to binary expression ('double' and 'int *') double a; int *b; void f(void) { int c = a + ~ ^ instead of: a.c:1:44: error: invalid operands to binary expression ('double' and 'int *') double a; int *b; void f(void) { int c = a + ~ ~ ^ for PR1906 (note the leading ~). Thanks to Neil for noticing this. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45901 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Driver/TextDiagnosticPrinter.cpp21
-rw-r--r--Driver/TextDiagnosticPrinter.h2
2 files changed, 15 insertions, 8 deletions
diff --git a/Driver/TextDiagnosticPrinter.cpp b/Driver/TextDiagnosticPrinter.cpp
index 11dbc42d23..16b348f78a 100644
--- a/Driver/TextDiagnosticPrinter.cpp
+++ b/Driver/TextDiagnosticPrinter.cpp
@@ -47,19 +47,23 @@ PrintIncludeStack(FullSourceLoc Pos) {
/// HighlightRange - Given a SourceRange and a line number, highlight (with ~'s)
/// any characters in LineNo that intersect the SourceRange.
void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
- SourceManager& SourceMgr,
- unsigned LineNo,
+ SourceManager& SourceMgr,
+ unsigned LineNo, unsigned FileID,
std::string &CaratLine,
const std::string &SourceLine) {
assert(CaratLine.size() == SourceLine.size() &&
"Expect a correspondence between source and carat line!");
if (!R.isValid()) return;
- unsigned StartLineNo = SourceMgr.getLogicalLineNumber(R.getBegin());
- if (StartLineNo > LineNo) return; // No intersection.
+ SourceLocation LogicalStart = SourceMgr.getLogicalLoc(R.getBegin());
+ unsigned StartLineNo = SourceMgr.getLineNumber(LogicalStart);
+ if (StartLineNo > LineNo || LogicalStart.getFileID() != FileID)
+ return; // No intersection.
- unsigned EndLineNo = SourceMgr.getLogicalLineNumber(R.getEnd());
- if (EndLineNo < LineNo) return; // No intersection.
+ SourceLocation LogicalEnd = SourceMgr.getLogicalLoc(R.getEnd());
+ unsigned EndLineNo = SourceMgr.getLineNumber(LogicalEnd);
+ if (EndLineNo < LineNo || LogicalStart.getFileID() != FileID)
+ return; // No intersection.
// Compute the column number of the start.
unsigned StartColNo = 0;
@@ -107,11 +111,13 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags,
const SourceRange *Ranges,
unsigned NumRanges) {
unsigned LineNo = 0, ColNo = 0;
+ unsigned FileID = 0;
const char *LineStart = 0, *LineEnd = 0;
if (Pos.isValid()) {
FullSourceLoc LPos = Pos.getLogicalLoc();
LineNo = LPos.getLineNumber();
+ FileID = LPos.getLocation().getFileID();
// First, if this diagnostic is not in the main file, print out the
// "included from" lines.
@@ -163,7 +169,8 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags,
// Highlight all of the characters covered by Ranges with ~ characters.
for (unsigned i = 0; i != NumRanges; ++i)
- HighlightRange(Ranges[i], Pos.getManager(),LineNo, CaratLine, SourceLine);
+ HighlightRange(Ranges[i], Pos.getManager(), LineNo, FileID,
+ CaratLine, SourceLine);
// Next, insert the carat itself.
if (ColNo-1 < CaratLine.size())
diff --git a/Driver/TextDiagnosticPrinter.h b/Driver/TextDiagnosticPrinter.h
index f74dd5d6bf..441f5ed80b 100644
--- a/Driver/TextDiagnosticPrinter.h
+++ b/Driver/TextDiagnosticPrinter.h
@@ -30,7 +30,7 @@ public:
void HighlightRange(const SourceRange &R,
SourceManager& SrcMgr,
- unsigned LineNo,
+ unsigned LineNo, unsigned FileID,
std::string &CaratLine,
const std::string &SourceLine);