From e4c6153cf199de5acdc62ca9ea54ccb7d0c203ff Mon Sep 17 00:00:00 2001 From: Nirav Dave Date: Sat, 1 Oct 2016 10:57:55 +0000 Subject: [PATCH] Revert "[MC] Prevent out of order HashDirective lexing in AsmLexer." This reverts commit r282992 which appears to be causing an LTO test failure. llvm-svn: 283034 --- llvm/include/llvm/MC/MCParser/AsmLexer.h | 2 +- llvm/lib/MC/MCParser/AsmLexer.cpp | 43 ++++++++++++++---------- llvm/test/MC/AsmParser/pr28921.s | 8 ----- 3 files changed, 27 insertions(+), 26 deletions(-) delete mode 100644 llvm/test/MC/AsmParser/pr28921.s diff --git a/llvm/include/llvm/MC/MCParser/AsmLexer.h b/llvm/include/llvm/MC/MCParser/AsmLexer.h index 029598c013d3..06937e25f59e 100644 --- a/llvm/include/llvm/MC/MCParser/AsmLexer.h +++ b/llvm/include/llvm/MC/MCParser/AsmLexer.h @@ -32,7 +32,7 @@ class AsmLexer : public MCAsmLexer { bool IsAtStartOfLine; bool IsAtStartOfStatement; bool IsParsingMSInlineAsm; - bool IsPeeking; + void operator=(const AsmLexer&) = delete; AsmLexer(const AsmLexer&) = delete; diff --git a/llvm/lib/MC/MCParser/AsmLexer.cpp b/llvm/lib/MC/MCParser/AsmLexer.cpp index 0fa7fbdc7b67..99e1df6be6e4 100644 --- a/llvm/lib/MC/MCParser/AsmLexer.cpp +++ b/llvm/lib/MC/MCParser/AsmLexer.cpp @@ -11,29 +11,29 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCParser/AsmLexer.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" -#include "llvm/MC/MCAsmInfo.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/MC/MCParser/AsmLexer.h" #include "llvm/MC/MCParser/MCAsmLexer.h" +#include "llvm/MC/MCAsmInfo.h" #include "llvm/Support/SMLoc.h" -#include "llvm/Support/SaveAndRestore.h" #include #include #include #include -#include #include +#include #include using namespace llvm; -AsmLexer::AsmLexer(const MCAsmInfo &MAI) - : MAI(MAI), CurPtr(nullptr), IsAtStartOfLine(true), - IsAtStartOfStatement(true), IsParsingMSInlineAsm(false), - IsPeeking(false) { +AsmLexer::AsmLexer(const MCAsmInfo &MAI) : MAI(MAI) { + CurPtr = nullptr; + IsAtStartOfLine = true; + IsAtStartOfStatement = true; + IsParsingMSInlineAsm = false; AllowAtInIdentifier = !StringRef(MAI.getCommentString()).startswith("@"); } @@ -487,15 +487,17 @@ StringRef AsmLexer::LexUntilEndOfLine() { size_t AsmLexer::peekTokens(MutableArrayRef Buf, bool ShouldSkipSpace) { - SaveAndRestore SavedTokenStart(TokStart); - SaveAndRestore SavedCurPtr(CurPtr); - SaveAndRestore SavedAtStartOfLine(IsAtStartOfLine); - SaveAndRestore SavedAtStartOfStatement(IsAtStartOfStatement); - SaveAndRestore SavedSkipSpace(SkipSpace, ShouldSkipSpace); - SaveAndRestore SavedIsPeeking(IsPeeking, true); + const char *SavedTokStart = TokStart; + const char *SavedCurPtr = CurPtr; + bool SavedAtStartOfLine = IsAtStartOfLine; + bool SavedAtStartOfStatement = IsAtStartOfStatement; + bool SavedSkipSpace = SkipSpace; + std::string SavedErr = getErr(); SMLoc SavedErrLoc = getErrLoc(); + SkipSpace = ShouldSkipSpace; + size_t ReadCount; for (ReadCount = 0; ReadCount < Buf.size(); ++ReadCount) { AsmToken Token = LexToken(); @@ -507,6 +509,13 @@ size_t AsmLexer::peekTokens(MutableArrayRef Buf, } SetError(SavedErrLoc, SavedErr); + + SkipSpace = SavedSkipSpace; + IsAtStartOfLine = SavedAtStartOfLine; + IsAtStartOfStatement = SavedAtStartOfStatement; + CurPtr = SavedCurPtr; + TokStart = SavedTokStart; + return ReadCount; } @@ -516,7 +525,7 @@ bool AsmLexer::isAtStartOfComment(const char *Ptr) { if (CommentString.size() == 1) return CommentString[0] == Ptr[0]; - // Allow # preprocessor commments also be counted as comments for "##" cases + // FIXME: special case for the bogus "##" comment string in X86MCAsmInfoDarwin if (CommentString[1] == '#') return CommentString[0] == Ptr[0]; @@ -533,7 +542,7 @@ AsmToken AsmLexer::LexToken() { // This always consumes at least one character. int CurChar = getNextChar(); - if (!IsPeeking && CurChar == '#' && IsAtStartOfStatement) { + if (CurChar == '#' && IsAtStartOfStatement) { // If this starts with a '#', this may be a cpp // hash directive and otherwise a line comment. AsmToken TokenBuf[2]; diff --git a/llvm/test/MC/AsmParser/pr28921.s b/llvm/test/MC/AsmParser/pr28921.s deleted file mode 100644 index 2fbb555f4f3e..000000000000 --- a/llvm/test/MC/AsmParser/pr28921.s +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: llvm-mc -triple i386-unknown-unknown %s - -# 1 "kernel.S" -# 1 "" 1 -# 1 "kernel.S" 2 -## -# 10 "kernel.S" -##