[PATCH] D107183: [Preprocessor] Ensure newline after #pragma introduced by -fms-extensions.
Michael Kruse via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 30 10:30:24 PDT 2021
Meinersbur created this revision.
Meinersbur added reviewers: aaron.ballman, dblaikie, mstorsjo, romanovvlad, alexfh.
Meinersbur added a project: clang.
Meinersbur requested review of this revision.
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 though that `ok::isAtStartOfLine() indicated that we should not start a newline.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107183
Files:
clang/lib/Frontend/PrintPreprocessedOutput.cpp
clang/test/Preprocessor/whitespace-ms-extensions.c
Index: clang/test/Preprocessor/whitespace-ms-extensions.c
===================================================================
--- /dev/null
+++ 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
Index: clang/lib/Frontend/PrintPreprocessedOutput.cpp
===================================================================
--- clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ 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))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107183.363139.patch
Type: text/x-patch
Size: 1442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210730/ad38d6f1/attachment.bin>
More information about the cfe-commits
mailing list