]> granicus.if.org Git - clang/commitdiff
Fix the indentation of the first line of preprocessor output
authorHal Finkel <hfinkel@anl.gov>
Mon, 28 Jan 2013 04:37:37 +0000 (04:37 +0000)
committerHal Finkel <hfinkel@anl.gov>
Mon, 28 Jan 2013 04:37:37 +0000 (04:37 +0000)
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.

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

lib/Frontend/PrintPreprocessedOutput.cpp
test/Preprocessor/first-line-indent.c [new file with mode: 0644]

index cc8d935b52f65409dd71b59b42c79ecb64be79d7..e7b64973ad58ac5c29b2230c789660c71e46b270 100644 (file)
@@ -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);
 
diff --git a/test/Preprocessor/first-line-indent.c b/test/Preprocessor/first-line-indent.c
new file mode 100644 (file)
index 0000000..d220d57
--- /dev/null
@@ -0,0 +1,7 @@
+       foo
+// RUN: %clang_cc1 -E %s | FileCheck -strict-whitespace %s
+       bar
+
+// CHECK: {{^       }}foo
+// CHECK: {{^       }}bar
+