Index: include/llvm/MC/MCParser/AsmLexer.h =================================================================== --- include/llvm/MC/MCParser/AsmLexer.h +++ include/llvm/MC/MCParser/AsmLexer.h @@ -32,7 +32,7 @@ bool IsAtStartOfLine; bool IsAtStartOfStatement; bool IsParsingMSInlineAsm; - + bool IsPeeking; void operator=(const AsmLexer&) = delete; AsmLexer(const AsmLexer&) = delete; Index: lib/MC/MCParser/AsmLexer.cpp =================================================================== --- lib/MC/MCParser/AsmLexer.cpp +++ lib/MC/MCParser/AsmLexer.cpp @@ -34,6 +34,7 @@ IsAtStartOfLine = true; IsAtStartOfStatement = true; IsParsingMSInlineAsm = false; + IsPeeking = false; AllowAtInIdentifier = !StringRef(MAI.getCommentString()).startswith("@"); } @@ -492,6 +493,8 @@ bool SavedAtStartOfLine = IsAtStartOfLine; bool SavedAtStartOfStatement = IsAtStartOfStatement; bool SavedSkipSpace = SkipSpace; + bool SavedIsPeeking = IsPeeking; + IsPeeking = true; std::string SavedErr = getErr(); SMLoc SavedErrLoc = getErrLoc(); @@ -515,7 +518,7 @@ IsAtStartOfStatement = SavedAtStartOfStatement; CurPtr = SavedCurPtr; TokStart = SavedTokStart; - + IsPeeking = SavedIsPeeking; return ReadCount; } @@ -542,7 +545,7 @@ // This always consumes at least one character. int CurChar = getNextChar(); - if (CurChar == '#' && IsAtStartOfStatement) { + if (!IsPeeking && CurChar == '#' && IsAtStartOfStatement) { // If this starts with a '#', this may be a cpp // hash directive and otherwise a line comment. AsmToken TokenBuf[2]; Index: test/MC/AsmParser/pr28921.s =================================================================== --- /dev/null +++ test/MC/AsmParser/pr28921.s @@ -0,0 +1,8 @@ +// RUN: llvm-mc -triple i386-unknown-unknown %s + +# 1 "kernel.S" +# 1 "" 1 +# 1 "kernel.S" 2 +## +# 10 "kernel.S" +##