Skip to content

Commit 646785d

Browse files
authored
Raise parse error on NaN in i32 and i64 literals (#2485)
Previously, the parser would return result::Error, but would not populate an error message.
1 parent e1d84ff commit 646785d

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/wast-parser.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,8 @@ Result WastParser::ParseConst(Const* const_, ConstType const_type) {
27812781
case Opcode::I32Const: {
27822782
auto token = Consume();
27832783
if (!token.HasLiteral()) {
2784-
return Result::Error;
2784+
result = Result::Error;
2785+
break;
27852786
}
27862787
auto sv = token.literal().text;
27872788
uint32_t u32;
@@ -2793,7 +2794,8 @@ Result WastParser::ParseConst(Const* const_, ConstType const_type) {
27932794
case Opcode::I64Const: {
27942795
auto token = Consume();
27952796
if (!token.HasLiteral()) {
2796-
return Result::Error;
2797+
result = Result::Error;
2798+
break;
27972799
}
27982800
auto sv = token.literal().text;
27992801
uint64_t u64;

test/spec/i32.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,5 +260,13 @@ out/test/spec/i32.wast:975: assert_invalid passed:
260260
out/test/spec/i32.wast:976: assert_invalid passed:
261261
out/test/spec/i32/i32.83.wasm:0000020: error: type mismatch in i32.ne, expected [i32, i32] but got [i64, f32]
262262
0000020: error: OnCompareExpr callback failed
263+
out/test/spec/i32.wast:979: assert_malformed passed:
264+
out/test/spec/i32/i32.84.wat:1:31: error: invalid literal "nan:arithmetic"
265+
(func (result i32) (i32.const nan:arithmetic))
266+
^^^^^^^^^^^^^^
267+
out/test/spec/i32.wast:983: assert_malformed passed:
268+
out/test/spec/i32/i32.85.wat:1:31: error: invalid literal "nan:canonical"
269+
(func (result i32) (i32.const nan:canonical))
270+
^^^^^^^^^^^^^
263271
460/460 tests passed.
264272
;;; STDOUT ;;)

test/spec/i64.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,13 @@ out/test/spec/i64.wast:484: assert_invalid passed:
9898
out/test/spec/i64.wast:485: assert_invalid passed:
9999
out/test/spec/i64/i64.29.wasm:0000020: error: type mismatch in i64.ne, expected [i64, i64] but got [i32, f32]
100100
0000020: error: OnCompareExpr callback failed
101+
out/test/spec/i64.wast:488: assert_malformed passed:
102+
out/test/spec/i64/i64.30.wat:1:31: error: invalid literal "nan:arithmetic"
103+
(func (result i64) (i64.const nan:arithmetic))
104+
^^^^^^^^^^^^^^
105+
out/test/spec/i64.wast:492: assert_malformed passed:
106+
out/test/spec/i64/i64.31.wat:1:31: error: invalid literal "nan:canonical"
107+
(func (result i64) (i64.const nan:canonical))
108+
^^^^^^^^^^^^^
101109
416/416 tests passed.
102110
;;; STDOUT ;;)

0 commit comments

Comments
 (0)