[PATCH] D92681: [MC] Fix ICE with non-newline terminated input
Scott Linder via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 4 12:54:32 PST 2020
scott.linder created this revision.
Herald added a subscriber: hiraditya.
scott.linder requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
There is an explicit option for the lexer to support this, but we crash
when `-preserve-comments` is enabled because it checks for
`getTok().getString().empty()` to detect the case. This doesn't
work currently because the lexer reports this case as a string of length
1, containing a null byte.
Change the lexer to instead report this case via an empty string, as the
null terminator isn't logically a part of the textual input, and the
check for `.empty()` seems natural and obvious in the calling code.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D92681
Files:
llvm/lib/MC/MCParser/AsmLexer.cpp
llvm/test/MC/AsmParser/Inputs/no-newline-at-end-of-file.s
llvm/test/MC/AsmParser/preserve-comments.s
Index: llvm/test/MC/AsmParser/preserve-comments.s
===================================================================
--- llvm/test/MC/AsmParser/preserve-comments.s
+++ llvm/test/MC/AsmParser/preserve-comments.s
@@ -1,5 +1,6 @@
#RUN: llvm-mc -preserve-comments -n -triple i386-linux-gnu < %s > %t
#RUN: diff -b %s %t
+ #RUN: llvm-mc -preserve-comments -n -triple i386-linux-gnu < %p/Inputs/no-newline-at-end-of-file.s | FileCheck %s
.text
foo: #Comment here
@@ -11,3 +12,6 @@
#endif
.ident "clang version 3.9.0"
.section ".note.GNU-stack","", at progbits
+
+ #Confirm we don't crash on inputs without a terminating newline.
+ #CHECK: .text
Index: llvm/test/MC/AsmParser/Inputs/no-newline-at-end-of-file.s
===================================================================
--- /dev/null
+++ llvm/test/MC/AsmParser/Inputs/no-newline-at-end-of-file.s
@@ -0,0 +1 @@
+.text
\ No newline at end of file
Index: llvm/lib/MC/MCParser/AsmLexer.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmLexer.cpp
+++ llvm/lib/MC/MCParser/AsmLexer.cpp
@@ -715,7 +715,7 @@
if (CurChar == EOF && !IsAtStartOfStatement && EndStatementAtEOF) {
IsAtStartOfLine = true;
IsAtStartOfStatement = true;
- return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1));
+ return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 0));
}
IsAtStartOfLine = false;
bool OldIsAtStartOfStatement = IsAtStartOfStatement;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92681.309625.patch
Type: text/x-patch
Size: 1482 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201204/73148943/attachment.bin>
More information about the llvm-commits
mailing list