[llvm-branch-commits] [cfe-branch] r73502 - /cfe/branches/Apple/Dib/lib/Frontend/TextDiagnosticPrinter.cpp

Daniel Dunbar daniel at zuster.org
Tue Jun 16 10:05:41 PDT 2009


Author: ddunbar
Date: Tue Jun 16 12:05:36 2009
New Revision: 73502

URL: http://llvm.org/viewvc/llvm-project?rev=73502&view=rev
Log:
Merge in 73378 (<rdar://problem/6939599>):

------------------------------------------------------------------------
r73378 | lattner | 2009-06-14 22:18:27 -0700 (Sun, 14 Jun 2009) | 27 lines

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

------------------------------------------------------------------------

Modified:
    cfe/branches/Apple/Dib/lib/Frontend/TextDiagnosticPrinter.cpp

Modified: cfe/branches/Apple/Dib/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Frontend/TextDiagnosticPrinter.cpp?rev=73502&r1=73501&r2=73502&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Frontend/TextDiagnosticPrinter.cpp Tue Jun 16 12:05:36 2009
@@ -614,9 +614,18 @@
 
           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





More information about the llvm-branch-commits mailing list