diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -646,7 +646,9 @@ !Tok.is(tok::annot_module_begin) && !Tok.is(tok::annot_module_end))) return; - if (!RequireSameLine && MoveToLine(Tok, /*RequireStartOfLine=*/false)) { + // EmittedDirectiveOnThisLine takes priority over RequireSameLine. + if ((!RequireSameLine || EmittedDirectiveOnThisLine) && + MoveToLine(Tok, /*RequireStartOfLine=*/EmittedDirectiveOnThisLine)) { if (MinimizeWhitespace) { // Avoid interpreting hash as a directive under -fpreprocessed. if (Tok.is(tok::hash)) diff --git a/clang/test/Preprocessor/whitespace-ms-extensions.c b/clang/test/Preprocessor/whitespace-ms-extensions.c new file mode 100644 --- /dev/null +++ b/clang/test/Preprocessor/whitespace-ms-extensions.c @@ -0,0 +1,18 @@ +// RUN: %clang -E -P %s -o -| FileCheck %s +// RUN: %clang -E -P -fms-extensions %s -o -| FileCheck %s --check-prefix=MSEXT + +// -fms-extensions changes __pragma into #pragma +// Ensure that there is a newline after the #pragma line. + +#define MACRO \ + __pragma(PRAGMA) \ + text + +beforetext MACRO aftertext + + +// CHECK: beforetext __pragma(PRAGMA) text aftertext + +// MSEXT: beforetext +// MSEXT: #pragma PRAGMA +// MSEXT-NEXT: text aftertext