aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/TextDiagnosticPrinter.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-06-15 05:18:27 +0000
committerChris Lattner <sabre@nondot.org>2009-06-15 05:18:27 +0000
commit81ebe9bf80b9a4eb1e5a30b0de39b2d638044ae4 (patch)
treebe7828470556126750a09b785c9d08a90017c0d7 /lib/Frontend/TextDiagnosticPrinter.cpp
parent6896a371e302c63ce3d4a99ad2c32e42dde6a9e4 (diff)
Minor tweak to -fdiagnostics-print-source-range-info to make it print
ranges more similar to the console output. Consider: #define FOO(X, Y) X/ Y void foo(int *P, int *Q) { FOO(P, Q); } Before we emitted: t.c:4:3:{4:3-4:6}{4:3-4:6}: error: invalid operands to binary expression ('int *' and 'int *') FOO(P, Q); ^~~~~~~~~ ... Note that while we underline the macro args that the range info just includes FOO without its macros. This change teaches the printed ranges to include macro args also so that we get: t.c:4:3:{4:3-4:12}{4:3-4:12}: error: invalid operands to binary expression ('int *' and 'int *') FOO(P, Q); ^~~~~~~~~ ... This fixes rdar://6939599 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73378 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/TextDiagnosticPrinter.cpp')
-rw-r--r--lib/Frontend/TextDiagnosticPrinter.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp
index 6699c65f52..d4c7e0f6f3 100644
--- a/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -640,9 +640,18 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
SourceLocation B = Info.getRange(i).getBegin();
SourceLocation E = Info.getRange(i).getEnd();
- std::pair<FileID, unsigned> BInfo=SM.getDecomposedInstantiationLoc(B);
-
+ B = SM.getInstantiationLoc(B);
E = SM.getInstantiationLoc(E);
+
+ // If the End location and the start location are the same and are a
+ // macro location, then the range was something that came from a macro
+ // expansion or _Pragma. If this is an object-like macro, the best we
+ // can do is to highlight the range. If this is a function-like
+ // macro, we'd also like to highlight the arguments.
+ if (B == E && Info.getRange(i).getEnd().isMacroID())
+ E = SM.getInstantiationRange(Info.getRange(i).getEnd()).second;
+
+ std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(B);
std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(E);
// If the start or end of the range is in another file, just discard