PR4288: Make -dD (dump macros with preprocessed source) play nicely with
# line directives.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72724 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp
index e79453c..89d099c 100644
--- a/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -87,6 +87,7 @@
private:
unsigned CurLine;
bool EmittedTokensOnThisLine;
+ bool EmittedMacroOnThisLine;
SrcMgr::CharacteristicKind FileType;
llvm::SmallString<512> CurFilename;
bool Initialized;
@@ -100,6 +101,7 @@
CurLine = 0;
CurFilename += "<uninit>";
EmittedTokensOnThisLine = false;
+ EmittedMacroOnThisLine = false;
FileType = SrcMgr::C_User;
Initialized = false;
}
@@ -130,9 +132,10 @@
void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
const char *Extra,
unsigned ExtraLen) {
- if (EmittedTokensOnThisLine) {
+ if (EmittedTokensOnThisLine || EmittedMacroOnThisLine) {
OS << '\n';
EmittedTokensOnThisLine = false;
+ EmittedMacroOnThisLine = false;
}
OS << '#' << ' ' << LineNo << ' ' << '"';
@@ -161,11 +164,12 @@
CurLine = LineNo;
- if (!EmittedTokensOnThisLine)
+ if (!EmittedTokensOnThisLine && !EmittedMacroOnThisLine)
return true;
OS << '\n';
EmittedTokensOnThisLine = false;
+ EmittedMacroOnThisLine = false;
return true;
}
@@ -260,6 +264,7 @@
MoveToLine(MI->getDefinitionLoc());
PrintMacroDefinition(*II, *MI, PP, OS);
+ EmittedMacroOnThisLine = true;
}
diff --git a/test/Preprocessor/dump-macros-spacing.c b/test/Preprocessor/dump-macros-spacing.c
new file mode 100644
index 0000000..335e37c
--- /dev/null
+++ b/test/Preprocessor/dump-macros-spacing.c
@@ -0,0 +1,13 @@
+// RUN: clang-cc -E -dD < %s | grep stdin | grep -v define
+#define A A
+/* 1
+ * 2
+ * 3
+ * 4
+ * 5
+ * 6
+ * 7
+ * 8
+ */
+#define B B
+