[PATCH] D18240: Asm preprocessor fix for unknown hash-lines
Andrew Zhogin via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 30 10:28:44 PDT 2017
andrew.zhogin updated this revision to Diff 104893.
andrew.zhogin added a comment.
Herald added a subscriber: aprantl.
Updated to the current repository state.
https://reviews.llvm.org/D18240
Files:
lib/Frontend/PrintPreprocessedOutput.cpp
test/Misc/asm_hash_comments.s
Index: test/Misc/asm_hash_comments.s
===================================================================
--- test/Misc/asm_hash_comments.s
+++ test/Misc/asm_hash_comments.s
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -E -x assembler-with-cpp %s | FileCheck --strict-whitespace %s
+// CHECK: # some comment 1
+// CHECK-NEXT: # some comment 2
+// CHECK-NEXT: # some comment 3
+
+# some comment 1
+# some comment 2
+# some comment 3
+
+
Index: lib/Frontend/PrintPreprocessedOutput.cpp
===================================================================
--- lib/Frontend/PrintPreprocessedOutput.cpp
+++ lib/Frontend/PrintPreprocessedOutput.cpp
@@ -96,6 +96,7 @@
bool DumpIncludeDirectives;
bool UseLineDirectives;
bool IsFirstFileEntered;
+ bool NewLinesInTokenHandled;
public:
PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os, bool lineMarkers,
bool defines, bool DumpIncludeDirectives,
@@ -111,6 +112,7 @@
FileType = SrcMgr::C_User;
Initialized = false;
IsFirstFileEntered = false;
+ NewLinesInTokenHandled = false;
}
void setEmittedTokensOnThisLine() { EmittedTokensOnThisLine = true; }
@@ -164,7 +166,7 @@
void WriteLineInfo(unsigned LineNo, const char *Extra=nullptr,
unsigned ExtraLen=0);
bool LineMarkersAreDisabled() const { return DisableLineMarkers; }
- void HandleNewlinesInToken(const char *TokStr, unsigned Len);
+ void HandleNewlinesInToken(const char *TokStr, unsigned Len, bool IsSp);
/// MacroDefined - This hook is called whenever a macro definition is seen.
void MacroDefined(const Token &MacroNameTok,
@@ -213,11 +215,13 @@
bool PrintPPOutputPPCallbacks::MoveToLine(unsigned LineNo) {
// If this line is "close enough" to the original line, just print newlines,
// otherwise print a #line directive.
+ bool WasNewLines = NewLinesInTokenHandled;
+ NewLinesInTokenHandled = false;
if (LineNo-CurLine <= 8) {
if (LineNo-CurLine == 1)
OS << '\n';
else if (LineNo == CurLine)
- return false; // Spelling line moved, but expansion line didn't.
+ return WasNewLines; // Spelling line moved, but expansion line didn't.
else {
const char *NewLines = "\n\n\n\n\n\n\n\n";
OS.write(NewLines, LineNo-CurLine);
@@ -588,7 +592,7 @@
}
void PrintPPOutputPPCallbacks::HandleNewlinesInToken(const char *TokStr,
- unsigned Len) {
+ unsigned Len, bool IsSp) {
unsigned NumNewlines = 0;
for (; Len; --Len, ++TokStr) {
if (*TokStr != '\n' &&
@@ -609,6 +613,7 @@
if (NumNewlines == 0) return;
CurLine += NumNewlines;
+ if (IsSp) NewLinesInTokenHandled = true;
}
@@ -736,15 +741,19 @@
// Tokens that can contain embedded newlines need to adjust our current
// line number.
if (Tok.getKind() == tok::comment || Tok.getKind() == tok::unknown)
- Callbacks->HandleNewlinesInToken(TokPtr, Len);
+ Callbacks->HandleNewlinesInToken(TokPtr, Len, false);
+ if (Tok.getKind() == tok::eod)
+ Callbacks->HandleNewlinesInToken(TokPtr, Len, true);
} else {
std::string S = PP.getSpelling(Tok);
OS.write(&S[0], S.size());
// Tokens that can contain embedded newlines need to adjust our current
// line number.
if (Tok.getKind() == tok::comment || Tok.getKind() == tok::unknown)
- Callbacks->HandleNewlinesInToken(&S[0], S.size());
+ Callbacks->HandleNewlinesInToken(&S[0], S.size(), false);
+ if (Tok.getKind() == tok::eod)
+ Callbacks->HandleNewlinesInToken(&S[0], S.size(), true);
}
Callbacks->setEmittedTokensOnThisLine();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18240.104893.patch
Type: text/x-patch
Size: 3735 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170630/223f2176/attachment.bin>
More information about the cfe-commits
mailing list