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() == false && + getTok().getString().front() != '\n' && getTok().getString().front() != '\r' && MAI.preserveAsmComments()) Out.addExplicitComment(Twine(getTok().getString())); } 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