diff --git a/llvm/include/llvm/MC/MCParser/MCAsmParser.h b/llvm/include/llvm/MC/MCParser/MCAsmParser.h --- a/llvm/include/llvm/MC/MCParser/MCAsmParser.h +++ b/llvm/include/llvm/MC/MCParser/MCAsmParser.h @@ -260,6 +260,8 @@ bool parseMany(function_ref parseOne, bool hasComma = true); + bool parseManyWithOptionalComma(function_ref parseOne); + bool parseIntToken(int64_t &V, const Twine &ErrMsg); bool check(bool P, const Twine &Msg); diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -3014,7 +3014,7 @@ return false; }; - if (parseMany(parseOp)) + if (parseManyWithOptionalComma(parseOp)) return addErrorSuffix(" in '" + Twine(IDVal) + "' directive"); return false; } diff --git a/llvm/lib/MC/MCParser/MCAsmParser.cpp b/llvm/lib/MC/MCParser/MCAsmParser.cpp --- a/llvm/lib/MC/MCParser/MCAsmParser.cpp +++ b/llvm/lib/MC/MCParser/MCAsmParser.cpp @@ -128,6 +128,21 @@ return false; } +bool MCAsmParser::parseManyWithOptionalComma(function_ref parseOne) { + if (parseOptionalToken(AsmToken::EndOfStatement)) + return false; + while (true) { + if (parseOne()) + return true; + if (parseOptionalToken(AsmToken::EndOfStatement)) + return false; + if (parseOptionalToken(AsmToken::Comma) && + check(getTok().isNot(AsmToken::String), "expected string")) + return true; + } + return false; +} + bool MCAsmParser::parseExpression(const MCExpr *&Res) { SMLoc L; return parseExpression(Res, L); diff --git a/llvm/test/MC/AsmParser/AArch64/directive-parse-err.s b/llvm/test/MC/AsmParser/AArch64/directive-parse-err.s --- a/llvm/test/MC/AsmParser/AArch64/directive-parse-err.s +++ b/llvm/test/MC/AsmParser/AArch64/directive-parse-err.s @@ -13,15 +13,15 @@ .set ident3, 0 $ // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error: .set ident3, 0 // EOL COMMENT - // CHECK: [[@LINE+1]]:20: error: unexpected token in '.ascii' directive + // CHECK: [[@LINE+1]]:20: error: expected string in '.ascii' directive .ascii "string1" $ // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error: .ascii "string1" // EOL COMMENT - // CHECK: [[@LINE+1]]:20: error: unexpected token in '.asciz' directive + // CHECK: [[@LINE+1]]:20: error: expected string in '.asciz' directive .asciz "string2" $ // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error: .asciz "string2" // EOL COMMENT - // CHECK: [[@LINE+1]]:20: error: unexpected token in '.string' directive + // CHECK: [[@LINE+1]]:20: error: expected string in '.string' directive .string "string3" $ // CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error: .string "string3" // EOL COMMENT diff --git a/llvm/test/MC/AsmParser/directive_ascii.s b/llvm/test/MC/AsmParser/directive_ascii.s --- a/llvm/test/MC/AsmParser/directive_ascii.s +++ b/llvm/test/MC/AsmParser/directive_ascii.s @@ -15,36 +15,64 @@ .ascii "A" # CHECK: TEST3: -# CHECK: .byte 66 -# CHECK: .byte 0 -# CHECK: .byte 67 -# CHECK: .byte 0 -TEST3: - .asciz "B", "C" - -# CHECK: TEST4: # CHECK: .asciz "\001\001\007\0008\001\0001\200" -TEST4: +TEST3: .ascii "\1\01\07\08\001\0001\200\0" -# CHECK: TEST5: +# CHECK: TEST4: # CHECK: .ascii "\b\f\n\r\t\\\"" -TEST5: +TEST4: .ascii "\b\f\n\r\t\\\"" +# CHECK: TEST5: +# CHECK: .ascii "dk" +# 0xFACE & 0xFF == 0xCE == 0o316 +# 0x0FE & 0xFF == 0xFE == 0o376 +# CHECK: .ascii "\316\376" +TEST5: + .ascii "\x64\Xa6B" + .ascii "\xface\x0Fe" + # CHECK: TEST6: +# CHECK: .byte 65 # CHECK: .byte 66 -# CHECK: .byte 0 # CHECK: .byte 67 -# CHECK: .byte 0 TEST6: - .string "B", "C" + .ascii "A", "B" "C" # CHECK: TEST7: -# CHECK: .ascii "dk" -# 0xFACE & 0xFF == 0xCE == 0o316 -# 0x0FE & 0xFF == 0xFE == 0o376 -# CHECK: .ascii "\316\376" +# CHECK: .ascii "ABC" TEST7: - .ascii "\x64\Xa6B" - .ascii "\xface\x0Fe" + .ascii "ABC" + +# CHECK: TEST8: +# CHECK: .byte 65 +# CHECK: .byte 0 +# CHECK: .byte 66 +# CHECK: .byte 0 +# CHECK: .byte 67 +# CHECK: .byte 0 +TEST8: + .asciz "A", "B" "C" + +# CHECK: TEST9: +# CHECK: .ascii "A\000B\000C" +# CHECK: .byte 0 +TEST9: + .asciz "A\0B\0C" + +# CHECK: TEST10: +# CHECK: .byte 65 +# CHECK: .byte 0 +# CHECK: .byte 66 +# CHECK: .byte 0 +# CHECK: .byte 67 +# CHECK: .byte 0 +TEST10: + .string "A", "B" "C" + +# CHECK: TEST11: +# CHECK: .ascii "A\000B\000C" +# CHECK: .byte 0 +TEST11: + .string "A\0B\0C" diff --git a/llvm/test/MC/Mips/asciiz-directive-bad.s b/llvm/test/MC/Mips/asciiz-directive-bad.s --- a/llvm/test/MC/Mips/asciiz-directive-bad.s +++ b/llvm/test/MC/Mips/asciiz-directive-bad.s @@ -3,6 +3,6 @@ .asciiz 12 # CHECK: :[[@LINE-1]]:11: error: expected string in '.asciiz' directive .asciiz "a"3 -# CHECK: :[[@LINE-1]]:14: error: unexpected token in '.asciiz' directive +# CHECK: :[[@LINE-1]]:14: error: expected string in '.asciiz' directive .asciiz "a", # CHECK: :[[@LINE-1]]:15: error: expected string in '.asciiz' directive