[clang] 0e25867 - [Preprocessor] Ensure newline after #pragma introduced by -fms-extensions.
Michael Kruse via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 1 17:09:46 PDT 2021
Author: Michael Kruse
Date: 2021-08-01T19:08:13-05:00
New Revision: 0e2586779ca6606a3df085f253a31b89b8ad8508
URL: https://github.com/llvm/llvm-project/commit/0e2586779ca6606a3df085f253a31b89b8ad8508
DIFF: https://github.com/llvm/llvm-project/commit/0e2586779ca6606a3df085f253a31b89b8ad8508.diff
LOG: [Preprocessor] Ensure newline after #pragma introduced by -fms-extensions.
The -fms-extensions converts __pragma (and _Pragma) into a #pragma that
has to occur at the beginning of a line and end with a newline. This
patch ensures that the newline after the #pragma is added even if
Token::isAtStartOfLine() indicated that we should not start a newline.
Committing relying post-commit review since the change is small, some
downstream uses might be blocked without this fix, and to make clear the
decision of the new -fminimize-whitespace feature (fix on main, revert
on clang-13.x branch) suggested by @aaron.ballman in D104601.
Differential Revision: https://reviews.llvm.org/D107183
Added:
clang/test/Preprocessor/whitespace-ms-extensions.c
Modified:
clang/lib/Frontend/PrintPreprocessedOutput.cpp
Removed:
################################################################################
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 1759485de24db..1a820ad985a4c 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -646,7 +646,9 @@ void PrintPPOutputPPCallbacks::HandleWhitespaceBeforeTok(const Token &Tok,
!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
index 0000000000000..5fd34fbc6a819
--- /dev/null
+++ b/clang/test/Preprocessor/whitespace-ms-extensions.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -E -P %s -o - | FileCheck %s
+// RUN: %clang_cc1 -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 \
+ text \
+ __pragma(PRAGMA) \
+ after
+
+before MACRO text
+
+
+// CHECK: before text __pragma(PRAGMA) after text
+
+// MSEXT: before text
+// MSEXT-NEXT: #pragma PRAGMA
+// MSEXT-NEXT: after text
More information about the cfe-commits
mailing list