diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-20 00:25:28 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-20 00:25:28 +0000 |
commit | 464ceb4ec8524517caa109397a59adcf4262947c (patch) | |
tree | fdc87bd647a55fb4bbdfa81485ea3d9d12de4cef /clang | |
parent | f5a5c4fa11c4ab1ea24293442a3d588794bff2c4 (diff) | |
download | bcm5719-llvm-464ceb4ec8524517caa109397a59adcf4262947c.tar.gz bcm5719-llvm-464ceb4ec8524517caa109397a59adcf4262947c.zip |
map source ranges through macro expansions. Before:
t.m:5:2: error: invalid operands to binary expression ('typeof(P)' (aka 'struct mystruct') and 'typeof(F)' (aka 'float'))
MAX(P, F);
^~~~~~~~~
t.m:1:78: note: instantiated from:
#define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
^
(no ranges on the second diagnostics)
After:
t.m:5:2: error: invalid operands to binary expression ('typeof(P)' (aka 'struct mystruct') and 'typeof(F)' (aka 'float'))
MAX(P, F);
^~~~~~~~~
t.m:1:78: note: instantiated from:
#define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
~~~ ^ ~~~
(ranges!)
llvm-svn: 65090
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Driver/TextDiagnosticPrinter.h | 2 | ||||
-rw-r--r-- | clang/lib/Driver/TextDiagnosticPrinter.cpp | 13 |
2 files changed, 13 insertions, 2 deletions
diff --git a/clang/include/clang/Driver/TextDiagnosticPrinter.h b/clang/include/clang/Driver/TextDiagnosticPrinter.h index 3f4f06a2c77..8d702b4934e 100644 --- a/clang/include/clang/Driver/TextDiagnosticPrinter.h +++ b/clang/include/clang/Driver/TextDiagnosticPrinter.h @@ -47,7 +47,7 @@ public: const std::string &SourceLine); void EmitCaretDiagnostic(SourceLocation Loc, - const SourceRange *Ranges, unsigned NumRanges, + SourceRange *Ranges, unsigned NumRanges, SourceManager &SM); virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, diff --git a/clang/lib/Driver/TextDiagnosticPrinter.cpp b/clang/lib/Driver/TextDiagnosticPrinter.cpp index 31b492a27a9..b5226f5131e 100644 --- a/clang/lib/Driver/TextDiagnosticPrinter.cpp +++ b/clang/lib/Driver/TextDiagnosticPrinter.cpp @@ -102,7 +102,7 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R, } void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc, - const SourceRange *Ranges, + SourceRange *Ranges, unsigned NumRanges, SourceManager &SM) { assert(!Loc.isInvalid() && "must have a valid source location here"); @@ -113,7 +113,18 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc, SourceLocation OneLevelUp = SM.getImmediateInstantiationRange(Loc).first; EmitCaretDiagnostic(OneLevelUp, Ranges, NumRanges, SM); + // Map the location through the macro. Loc = SM.getInstantiationLoc(SM.getImmediateSpellingLoc(Loc)); + + // Map the ranges. + for (unsigned i = 0; i != NumRanges; ++i) { + SourceLocation S = Ranges[i].getBegin(), E = Ranges[i].getEnd(); + if (S.isMacroID()) + S = SM.getInstantiationLoc(SM.getImmediateSpellingLoc(S)); + if (E.isMacroID()) + E = SM.getInstantiationLoc(SM.getImmediateSpellingLoc(E)); + Ranges[i] = SourceRange(S, E); + } // Emit the file/line/column that this expansion came from. OS << SM.getBufferName(Loc) << ':' << SM.getInstantiationLineNumber(Loc) |