]> granicus.if.org Git - clang/commitdiff
map source ranges through macro expansions. Before:
authorChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 00:25:28 +0000 (00:25 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 00:25:28 +0000 (00:25 +0000)
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!)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65090 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/TextDiagnosticPrinter.h
lib/Driver/TextDiagnosticPrinter.cpp

index 3f4f06a2c775eeb05915ef92cb2af71c72550229..8d702b4934e11164ec0bc608065828e236379bd3 100644 (file)
@@ -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,
index 31b492a27a9959daeaa894f47b1ddde1b4ef2f2d..b5226f5131e2c1a151bc1e4b52735022397dfda3 100644 (file)
@@ -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)