Index: lib/MC/MCParser/AsmParser.cpp =================================================================== --- lib/MC/MCParser/AsmParser.cpp +++ lib/MC/MCParser/AsmParser.cpp @@ -234,6 +234,8 @@ void eatToEndOfStatement() override; void checkForValidSection() override; + + bool parseEscapedString(std::string &Data) override; /// } private: @@ -442,7 +444,6 @@ bool parseDirectiveElseIf(SMLoc DirectiveLoc); // ".elseif" bool parseDirectiveElse(SMLoc DirectiveLoc); // ".else" bool parseDirectiveEndIf(SMLoc DirectiveLoc); // .endif - bool parseEscapedString(std::string &Data) override; const MCExpr *applyModifierToExpr(const MCExpr *E, MCSymbolRefExpr::VariantKind Variant); Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp =================================================================== --- lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -4287,6 +4287,51 @@ if (IDVal == ".module") return parseDirectiveModule(); + // .asciiz is exactly the same as .asciz, except it's MIPS-specific. + // Because of this, the following code is pretty much the same as + // AsmParser::parseDirectiveAscii. + if (IDVal == ".asciiz") { + if (getLexer().isNot(AsmToken::EndOfStatement)) { + Parser.checkForValidSection(); + + for (;;) { + // Check if it's actually a string. + if (getLexer().isNot(AsmToken::String)) { + reportParseError("expected string"); + return false; + } + + // Parse the string. + std::string Data; + if (Parser.parseEscapedString(Data)) + return true; + + // Emit the string and a trailing null byte. + getStreamer().EmitBytes(StringRef(Data)); + getStreamer().EmitBytes(StringRef("\0", 1)); + + getParser().Lex(); // Lex the Comma/EndOfStatement. + + // Check if we're finished. + if (getLexer().is(AsmToken::EndOfStatement)) + break; + + if (getLexer().isNot(AsmToken::Comma)) { + reportParseError("unexpected token, expected comma"); + return false; + } + + getParser().Lex(); // Lex the next String. + + if (getLexer().is(AsmToken::EndOfStatement)) { + Warning(Parser.getTok().getLoc(), "no string after comma"); + return false; + } + } + } + return false; + } // End of .asciiz. + return true; } Index: test/MC/Mips/asciiz-directive-bad.s =================================================================== --- /dev/null +++ test/MC/Mips/asciiz-directive-bad.s @@ -0,0 +1,10 @@ +# RUN: not llvm-mc -triple mips-unknown-linux %s 2>&1 | FileCheck %s + + .asciiz 12 +# CHECK: :[[@LINE-1]]:11: error: expected string + + .asciiz "a"3 +# CHECK: :[[@LINE-1]]:14: error: unexpected token, expected comma + + .asciiz "a", +# CHECK: :[[@LINE-1]]:15: warning: no string after comma Index: test/MC/Mips/asciiz-directive.s =================================================================== --- /dev/null +++ test/MC/Mips/asciiz-directive.s @@ -0,0 +1,28 @@ +# RUN: llvm-mc -triple mips-unknown-linux %s | FileCheck %s +# .asciiz is exactly the same as .asciz, except it's MIPS-specific. + +t1: + .asciiz +# CHECK-LABEL: t1 + +t2: + .asciiz "a" +# CHECK-LABEL: t2 +# CHECK: .byte 97 +# CHECK: .byte 0 + +t3: + .asciiz "a", "b", "c" +# CHECK-LABEL: t3 +# CHECK: .byte 97 +# CHECK: .byte 0 +# CHECK: .byte 98 +# CHECK: .byte 0 +# CHECK: .byte 99 +# CHECK: .byte 0 + +t4: + .asciiz "abcdefghijklmnop" +# CHECK-LABEL: t4 +# CHECK: .ascii "abcdefghijklmnop" +# CHECK: .byte 0