diff --git a/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp index c0abd11a504..e22ed8e4764 100644 --- a/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ b/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -665,13 +665,18 @@ public: return expect(AsmToken::EndOfStatement, "EOL"); } - if (DirectiveID.getString() == ".int8") { + if (DirectiveID.getString() == ".int8" || + DirectiveID.getString() == ".int16" || + DirectiveID.getString() == ".int32" || + DirectiveID.getString() == ".int64") { if (CheckDataSection()) return true; - int64_t V; - if (Parser.parseAbsoluteExpression(V)) - return error("Cannot parse int8 constant: ", Lexer.getTok()); - // TODO: error if value doesn't fit? - Out.EmitIntValue(static_cast(V), 1); + const MCExpr *Val; + SMLoc End; + if (Parser.parseExpression(Val, End)) + return error("Cannot parse .int expression: ", Lexer.getTok()); + size_t NumBits = 0; + DirectiveID.getString().drop_front(4).getAsInteger(10, NumBits); + Out.EmitValue(Val, NumBits / 8, End); return expect(AsmToken::EndOfStatement, "EOL"); } diff --git a/test/MC/WebAssembly/basic-assembly.s b/test/MC/WebAssembly/basic-assembly.s index 40c50d52ae2..75147319e26 100644 --- a/test/MC/WebAssembly/basic-assembly.s +++ b/test/MC/WebAssembly/basic-assembly.s @@ -95,7 +95,10 @@ test0: .L.str: .int8 'H' .asciz "ello, World!" - .size .L.str, 14 + .int16 1234 + .int64 5000000000 + .int32 2000000000 + .size .L.str, 28 .ident "clang version 9.0.0 (trunk 364502) (llvm/trunk 364571)" .globaltype __stack_pointer, i32 @@ -185,5 +188,8 @@ test0: # CHECK-NEXT: .L.str: # CHECK-NEXT: .int8 72 # CHECK-NEXT: .asciz "ello, World!" +# CHECK-NEXT: .int16 1234 +# CHECK-NEXT: .int64 5000000000 +# CHECK-NEXT: .int32 2000000000 # CHECK: .globaltype __stack_pointer, i32