Index: lib/MC/MCAsmStreamer.cpp =================================================================== --- lib/MC/MCAsmStreamer.cpp +++ lib/MC/MCAsmStreamer.cpp @@ -428,7 +428,7 @@ ie = Options.end(); it != ie; ++it) { OS << ", " << '"' << *it << '"'; } - OS << "\n"; + EmitEOL(); } void MCAsmStreamer::EmitDataRegion(MCDataRegionType Kind) { @@ -614,7 +614,7 @@ Symbol->print(OS, MAI); OS << ", "; Value->print(OS, MAI); - OS << '\n'; + EmitEOL(); } void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, @@ -1243,10 +1243,10 @@ void MCAsmStreamer::EmitCFIGnuArgsSize(int64_t Size) { MCStreamer::EmitCFIGnuArgsSize(Size); - + uint8_t Buffer[16] = { dwarf::DW_CFA_GNU_args_size }; unsigned Len = encodeULEB128(Size, Buffer + 1) + 1; - + PrintCFIEscape(OS, StringRef((const char *)&Buffer[0], Len)); EmitEOL(); } Index: lib/MC/MCParser/AsmParser.cpp =================================================================== --- lib/MC/MCParser/AsmParser.cpp +++ lib/MC/MCParser/AsmParser.cpp @@ -2990,6 +2990,7 @@ if (getLexer().isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.file' directive"); + Lex(); if (FileNumber == -1) getStreamer().EmitFileDirective(Filename); @@ -3022,6 +3023,7 @@ if (getLexer().isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.line' directive"); + Lex(); return false; } @@ -3120,6 +3122,7 @@ break; } } + Lex(); getStreamer().EmitDwarfLocDirective(FileNumber, LineNumber, ColumnPos, Flags, Isa, Discriminator, StringRef()); @@ -3230,6 +3233,7 @@ return Error(Loc, "unknown sub-directive in '.cv_loc' directive"); } } + Lex(); getStreamer().EmitCVLocDirective(FunctionId, FileNumber, LineNumber, ColumnPos, PrologueEnd, IsStmt, StringRef()); @@ -3320,6 +3324,8 @@ SecondaryFunctionIds.push_back(SecondaryFunctionId); } } + if (getLexer().is(AsmToken::EndOfStatement)) + Lex(); getStreamer().EmitCVInlineLinetableDirective(PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, @@ -3410,9 +3416,11 @@ /// ::= .cfi_startproc [simple] bool AsmParser::parseDirectiveCFIStartProc() { StringRef Simple; - if (getLexer().isNot(AsmToken::EndOfStatement)) + if (getLexer().isNot(AsmToken::EndOfStatement)) { if (parseIdentifier(Simple) || Simple != "simple") return TokError("unexpected token in .cfi_startproc directive"); + } else + Lex(); getStreamer().EmitCFIStartProc(!Simple.empty()); return false; @@ -3677,6 +3685,8 @@ if (getLexer().isNot(AsmToken::EndOfStatement)) return Error(getLexer().getLoc(), "unexpected token in '.cfi_signal_frame'"); + else + Lex(); getStreamer().EmitCFISignalFrame(); return false; @@ -3701,6 +3711,8 @@ if (getLexer().isNot(AsmToken::EndOfStatement)) return Error(getLexer().getLoc(), "unexpected token in '" + Directive + "' directive"); + else + Lex(); setMacrosEnabled(Directive == ".macros_on"); return false; @@ -3930,6 +3942,8 @@ bool AsmParser::parseDirectiveExitMacro(StringRef Directive) { if (getLexer().isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '" + Directive + "' directive"); + else + Lex(); if (!isInsideMacroInstantiation()) return TokError("unexpected '" + Directive + "' in file, " @@ -3951,6 +3965,8 @@ bool AsmParser::parseDirectiveEndMacro(StringRef Directive) { if (getLexer().isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '" + Directive + "' directive"); + else + Lex(); // If we are inside a macro instantiation, terminate the current // instantiation. @@ -3974,6 +3990,8 @@ if (getLexer().isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.purgem' directive"); + else + Lex(); if (!lookupMacro(Name)) return Error(DirectiveLoc, "macro '" + Name + "' is not defined"); @@ -4103,6 +4121,8 @@ return TokError("unexpected token in directive"); Lex(); } + if (getLexer().is(AsmToken::EndOfStatement)) + Lex(); return false; } Index: lib/MC/MCParser/ELFAsmParser.cpp =================================================================== --- lib/MC/MCParser/ELFAsmParser.cpp +++ lib/MC/MCParser/ELFAsmParser.cpp @@ -212,6 +212,7 @@ if (getLexer().isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in directive"); + Lex(); getStreamer().emitELFSize(Sym, Expr); return false; @@ -478,6 +479,7 @@ EndStmt: if (getLexer().isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in directive"); + Lex(); unsigned Type = ELF::SHT_PROGBITS; @@ -629,6 +631,10 @@ Lex(); + if (getLexer().isNot(AsmToken::EndOfStatement)) + return TokError("unexpected token in '.ident' directive"); + Lex(); + getStreamer().EmitIdent(Data); return false; } @@ -727,6 +733,8 @@ if (getLexer().isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in directive"); + Lex(); + getStreamer().SubSection(Subsection); return false; } Index: test/MC/AsmParser/preserve-comments.s =================================================================== --- test/MC/AsmParser/preserve-comments.s +++ test/MC/AsmParser/preserve-comments.s @@ -9,3 +9,5 @@ ## WHOLE LINE COMMENT cmpl $196, %eax ## EOL COMMENT #endif + .ident "clang version 3.9.0" + .section ".note.GNU-stack","",@progbits