[cfe-commits] r65090 - in /cfe/trunk: include/clang/Driver/TextDiagnosticPrinter.h lib/Driver/TextDiagnosticPrinter.cpp

Chris Lattner sabre at nondot.org
Thu Feb 19 16:25:28 PST 2009


Author: lattner
Date: Thu Feb 19 18:25:28 2009
New Revision: 65090

URL: http://llvm.org/viewvc/llvm-project?rev=65090&view=rev
Log:
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!)


Modified:
    cfe/trunk/include/clang/Driver/TextDiagnosticPrinter.h
    cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp

Modified: cfe/trunk/include/clang/Driver/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/TextDiagnosticPrinter.h?rev=65090&r1=65089&r2=65090&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/include/clang/Driver/TextDiagnosticPrinter.h Thu Feb 19 18:25:28 2009
@@ -47,7 +47,7 @@
                       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,

Modified: cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp?rev=65090&r1=65089&r2=65090&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp Thu Feb 19 18:25:28 2009
@@ -102,7 +102,7 @@
 }
 
 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 @@
     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)





More information about the cfe-commits mailing list