diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index cc8d935b52f6..e7b64973ad58 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -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/clang/test/Preprocessor/first-line-indent.c b/clang/test/Preprocessor/first-line-indent.c new file mode 100644 index 000000000000..d220d57a2820 --- /dev/null +++ b/clang/test/Preprocessor/first-line-indent.c @@ -0,0 +1,7 @@ + foo +// RUN: %clang_cc1 -E %s | FileCheck -strict-whitespace %s + bar + +// CHECK: {{^ }}foo +// CHECK: {{^ }}bar +