diff --git a/llvm/.gitattributes b/llvm/.gitattributes index 48ddf2f02d15..b41ae6aec97b 100644 --- a/llvm/.gitattributes +++ b/llvm/.gitattributes @@ -13,7 +13,8 @@ test/tools/llvm-strings/Inputs/numbers binary test/MC/AsmParser/incbin_abcd binary test/YAMLParser/spec-09-02.test binary -# This file must have CRLF line endings, therefore git should treat it as +# These files must have CRLF line endings, therefore git should treat them as # binary and not autoconvert line endings (for example, when core.autocrlf is # on). test/MC/AsmParser/preserve-comments-crlf.s binary +test/tools/llvm-mca/directives-handle-crlf.s binary diff --git a/llvm/lib/MC/MCParser/AsmLexer.cpp b/llvm/lib/MC/MCParser/AsmLexer.cpp index e328ba5315af..bf9b9e916d6f 100644 --- a/llvm/lib/MC/MCParser/AsmLexer.cpp +++ b/llvm/lib/MC/MCParser/AsmLexer.cpp @@ -228,6 +228,7 @@ AsmToken AsmLexer::LexLineComment() { int CurChar = getNextChar(); while (CurChar != '\n' && CurChar != '\r' && CurChar != EOF) CurChar = getNextChar(); + const char *NewlinePtr = CurPtr; if (CurChar == '\r' && CurPtr != CurBuf.end() && *CurPtr == '\n') ++CurPtr; @@ -235,7 +236,7 @@ AsmToken AsmLexer::LexLineComment() { if (CommentConsumer) { CommentConsumer->HandleComment( SMLoc::getFromPointer(CommentTextStart), - StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart)); + StringRef(CommentTextStart, NewlinePtr - 1 - CommentTextStart)); } IsAtStartOfLine = true; diff --git a/llvm/test/tools/llvm-mca/directives-handle-crlf.s b/llvm/test/tools/llvm-mca/directives-handle-crlf.s new file mode 100644 index 000000000000..aa5c0fc205f5 --- /dev/null +++ b/llvm/test/tools/llvm-mca/directives-handle-crlf.s @@ -0,0 +1,4 @@ +# RUN: llvm-mca -mtriple=x86_64-unknown-unknown %s +# LLVM-MCA-BEGIN foo +addl $42, %eax +# LLVM-MCA-END