Index: include/llvm/MC/MCParser/AsmLexer.h =================================================================== --- include/llvm/MC/MCParser/AsmLexer.h +++ include/llvm/MC/MCParser/AsmLexer.h @@ -49,7 +49,7 @@ const AsmToken peekTok(bool ShouldSkipSpace = true) override; - bool isAtStartOfComment(char Char); + bool isAtStartOfComment(const char *Ptr); bool isAtStatementSeparator(const char *Ptr); const MCAsmInfo &getMAI() const { return MAI; } Index: lib/MC/MCParser/AsmLexer.cpp =================================================================== --- lib/MC/MCParser/AsmLexer.cpp +++ lib/MC/MCParser/AsmLexer.cpp @@ -417,7 +417,7 @@ StringRef AsmLexer::LexUntilEndOfStatement() { TokStart = CurPtr; - while (!isAtStartOfComment(*CurPtr) && // Start of line comment. + while (!isAtStartOfComment(CurPtr) && // Start of line comment. !isAtStatementSeparator(CurPtr) && // End of statement marker. *CurPtr != '\n' && *CurPtr != '\r' && (*CurPtr != 0 || CurPtr != CurBuf.end())) { @@ -458,9 +458,16 @@ return Token; } -bool AsmLexer::isAtStartOfComment(char Char) { - // FIXME: This won't work for multi-character comment indicators like "//". - return Char == *MAI.getCommentString(); +bool AsmLexer::isAtStartOfComment(const char *Ptr) { + const char *CommentString = MAI.getCommentString(); + + if (CommentString[1] == '\0') + return CommentString[0] == Ptr[0]; + + if (CommentString[1] == '#') + // FIXME: special case for the bogus comment string in X86MCAsmInfoDarwin + return CommentString[0] == Ptr[0]; + return strncmp(Ptr, CommentString, strlen(CommentString)) == 0; } bool AsmLexer::isAtStatementSeparator(const char *Ptr) { @@ -473,7 +480,7 @@ // This always consumes at least one character. int CurChar = getNextChar(); - if (isAtStartOfComment(CurChar)) { + if (isAtStartOfComment(TokStart)) { // If this comment starts with a '#', then return the Hash token and let // the assembler parser see if it can be parsed as a cpp line filename // comment. We do this only if we are at the start of a line. Index: test/MC/AArch64/single-slash.s =================================================================== --- /dev/null +++ test/MC/AArch64/single-slash.s @@ -0,0 +1,6 @@ +// RUN: llvm-mc -triple aarch64-none-linux-gnu < %s | FileCheck %s + +// Test that a single slash is not mistaken as the start of comment. + +//CHECK: movz x0, #0x10 + movz x0, #(32 / 2)