[PATCH] D33993: Fix compiler crash in AsmParser::Lex
Alexandru Guduleasa via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 7 08:51:52 PDT 2017
alexandru.guduleasa updated this revision to Diff 101748.
alexandru.guduleasa added a comment.
Updated as per comments.
https://reviews.llvm.org/D33993
Files:
lib/MC/MCParser/AsmParser.cpp
test/MC/AsmParser/empty-comment.s
Index: test/MC/AsmParser/empty-comment.s
===================================================================
--- /dev/null
+++ test/MC/AsmParser/empty-comment.s
@@ -0,0 +1,4 @@
+ #RUN: llvm-mc -preserve-comments -n -triple i386-linux-gnu < %s > %t
+ .text
+foo:
+ nop #
\ No newline at end of file
Index: lib/MC/MCParser/AsmParser.cpp
===================================================================
--- lib/MC/MCParser/AsmParser.cpp
+++ lib/MC/MCParser/AsmParser.cpp
@@ -700,7 +700,8 @@
// if it's a end of statement with a comment in it
if (getTok().is(AsmToken::EndOfStatement)) {
// if this is a line comment output it.
- if (getTok().getString().front() != '\n' &&
+ if (!getTok().getString().empty() &&
+ getTok().getString().front() != '\n' &&
getTok().getString().front() != '\r' && MAI.preserveAsmComments())
Out.addExplicitComment(Twine(getTok().getString()));
}
@@ -1483,7 +1484,8 @@
Lex();
if (Lexer.is(AsmToken::EndOfStatement)) {
// if this is a line comment we can drop it safely
- if (getTok().getString().front() == '\r' ||
+ if (getTok().getString().empty() ||
+ getTok().getString().front() == '\r' ||
getTok().getString().front() == '\n')
Out.AddBlankLine();
Lex();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33993.101748.patch
Type: text/x-patch
Size: 1279 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170607/aacb70fd/attachment.bin>
More information about the llvm-commits
mailing list