forked from OSchip/llvm-project
[MCParser] Correctly handle CRLF line ends when consuming line comments
Fixes issue: https://bugs.llvm.org/show_bug.cgi?id=47983 The AsmLexer currently has an issue with lexing line comments in files with CRLF line endings, in which it reads the carriage return as being part of the line comment. This causes an error for certain valid comment layouts; this patch fixes this by excluding the carriage return from the line comment. Differential Revision: https://reviews.llvm.org/D90234
This commit is contained in:
parent
c67f497e7a
commit
5c6f748cbc
|
@ -13,7 +13,8 @@ test/tools/llvm-strings/Inputs/numbers binary
|
||||||
test/MC/AsmParser/incbin_abcd binary
|
test/MC/AsmParser/incbin_abcd binary
|
||||||
test/YAMLParser/spec-09-02.test 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
|
# binary and not autoconvert line endings (for example, when core.autocrlf is
|
||||||
# on).
|
# on).
|
||||||
test/MC/AsmParser/preserve-comments-crlf.s binary
|
test/MC/AsmParser/preserve-comments-crlf.s binary
|
||||||
|
test/tools/llvm-mca/directives-handle-crlf.s binary
|
||||||
|
|
|
@ -228,6 +228,7 @@ AsmToken AsmLexer::LexLineComment() {
|
||||||
int CurChar = getNextChar();
|
int CurChar = getNextChar();
|
||||||
while (CurChar != '\n' && CurChar != '\r' && CurChar != EOF)
|
while (CurChar != '\n' && CurChar != '\r' && CurChar != EOF)
|
||||||
CurChar = getNextChar();
|
CurChar = getNextChar();
|
||||||
|
const char *NewlinePtr = CurPtr;
|
||||||
if (CurChar == '\r' && CurPtr != CurBuf.end() && *CurPtr == '\n')
|
if (CurChar == '\r' && CurPtr != CurBuf.end() && *CurPtr == '\n')
|
||||||
++CurPtr;
|
++CurPtr;
|
||||||
|
|
||||||
|
@ -235,7 +236,7 @@ AsmToken AsmLexer::LexLineComment() {
|
||||||
if (CommentConsumer) {
|
if (CommentConsumer) {
|
||||||
CommentConsumer->HandleComment(
|
CommentConsumer->HandleComment(
|
||||||
SMLoc::getFromPointer(CommentTextStart),
|
SMLoc::getFromPointer(CommentTextStart),
|
||||||
StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart));
|
StringRef(CommentTextStart, NewlinePtr - 1 - CommentTextStart));
|
||||||
}
|
}
|
||||||
|
|
||||||
IsAtStartOfLine = true;
|
IsAtStartOfLine = true;
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
# RUN: llvm-mca -mtriple=x86_64-unknown-unknown %s
|
||||||
|
# LLVM-MCA-BEGIN foo
|
||||||
|
addl $42, %eax
|
||||||
|
# LLVM-MCA-END
|
Loading…
Reference in New Issue