[cfe-commits] r173657 - Fix the indentation of the first line of preprocessor output

Hal Finkel hfinkel at anl.gov
Sun Jan 27 20:37:37 PST 2013


Author: hfinkel
Date: Sun Jan 27 22:37:37 2013
New Revision: 173657

URL: http://llvm.org/viewvc/llvm-project?rev=173657&view=rev
Log:
Fix the indentation of the first line of preprocessor output

The -E output from clang did not produce the correct indentation on the first line.
This is because MoveToLine returned false, and when this happens,
the regular process for producing initial indentation is skipped.

Thanks to Eli for suggesting a way to simplify this to a one-line change.

Added:
    cfe/trunk/test/Preprocessor/first-line-indent.c
Modified:
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=173657&r1=173656&r2=173657&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Sun Jan 27 22:37:37 2013
@@ -139,11 +139,15 @@ public:
                                 diag::Mapping Map, StringRef Str);
 
   bool HandleFirstTokOnLine(Token &Tok);
+
+  /// Move to the line of the provided source location. This will
+  /// return true if the output stream required adjustment or if
+  /// the requested location is on the first line.
   bool MoveToLine(SourceLocation Loc) {
     PresumedLoc PLoc = SM.getPresumedLoc(Loc);
     if (PLoc.isInvalid())
       return false;
-    return MoveToLine(PLoc.getLine());
+    return MoveToLine(PLoc.getLine()) || (PLoc.getLine() == 1);
   }
   bool MoveToLine(unsigned LineNo);
 

Added: cfe/trunk/test/Preprocessor/first-line-indent.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/first-line-indent.c?rev=173657&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/first-line-indent.c (added)
+++ cfe/trunk/test/Preprocessor/first-line-indent.c Sun Jan 27 22:37:37 2013
@@ -0,0 +1,7 @@
+       foo
+// RUN: %clang_cc1 -E %s | FileCheck -strict-whitespace %s
+       bar
+
+// CHECK: {{^       }}foo
+// CHECK: {{^       }}bar
+





More information about the cfe-commits mailing list