From c6abe22cc0c6efe3ea6216345ba8437d6977a45b Mon Sep 17 00:00:00 2001 From: Shen-Ta Hsieh Date: Thu, 26 Nov 2026 07:12:24 +0800 Subject: [PATCH 1/7] [test] Add cases for malformed type uses A type use has at most one (type x) clause, and that clause holds exactly one type index. Add cases with two clauses, two indices, an extra field, and no index. --- test/core/func.wast | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/core/func.wast b/test/core/func.wast index f2d18cc9f1..adf7f1cee3 100644 --- a/test/core/func.wast +++ b/test/core/func.wast @@ -627,6 +627,23 @@ "inline function type" ) +(assert_malformed + (module quote "(type $t (func)) (func (type $t) (type $t))") + "unexpected token" +) +(assert_malformed + (module quote "(type $t (func)) (type $u (func)) (func (type $t $u))") + "unexpected token" +) +(assert_malformed + (module quote "(type $t (func)) (func (type $t (foo)))") + "unexpected token" +) +(assert_malformed + (module quote "(type $t (func)) (func (type))") + "unexpected token" +) + (assert_invalid (module (func $g (type 4))) "unknown type" From d82eb83dd88fe6c5130da967d36e8b7be7359f14 Mon Sep 17 00:00:00 2001 From: Shen-Ta Hsieh Date: Thu, 26 Nov 2026 07:12:24 +0800 Subject: [PATCH 2/7] [test] Add cases for malformed locals A local with an id declares exactly one value type. Add cases with no type and with two ids. --- test/core/func.wast | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/core/func.wast b/test/core/func.wast index adf7f1cee3..176b7839d7 100644 --- a/test/core/func.wast +++ b/test/core/func.wast @@ -976,6 +976,15 @@ "unexpected token" ) +(assert_malformed + (module quote "(func (local $x))") + "unexpected token" +) +(assert_malformed + (module quote "(func (local $x $y i32))") + "unexpected token" +) + ;; Duplicate name errors (assert_malformed From afe42f6905424e730107d56cc757e333725fc686 Mon Sep 17 00:00:00 2001 From: Shen-Ta Hsieh Date: Thu, 26 Nov 2026 07:12:24 +0800 Subject: [PATCH 3/7] [test] Add cases for a stray else or end The else and end keywords belong to block instructions, and an if has at most one else. Add cases with a second else, and with an else or an end that has no open block, in plain and folded form. --- test/core/func.wast | 24 ++++++++++++++++++++++++ test/core/if.wast | 17 +++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/test/core/func.wast b/test/core/func.wast index 176b7839d7..7be7ba8204 100644 --- a/test/core/func.wast +++ b/test/core/func.wast @@ -984,6 +984,30 @@ (module quote "(func (local $x $y i32))") "unexpected token" ) +(assert_malformed + (module quote "(func end)") + "unexpected token" +) +(assert_malformed + (module quote "(func (result i32) i32.const 1 end unreachable)") + "unexpected token" +) +(assert_malformed + (module quote "(func (end))") + "unexpected token" +) +(assert_malformed + (module quote "(func (end (nop)))") + "unexpected token" +) +(assert_malformed + (module quote "(func (block end) unreachable)") + "unexpected token" +) +(assert_malformed + (module quote "(func (block (end)))") + "unexpected token" +) ;; Duplicate name errors diff --git a/test/core/if.wast b/test/core/if.wast index 35a4cf6cb9..9ddd27c2ee 100644 --- a/test/core/if.wast +++ b/test/core/if.wast @@ -1562,3 +1562,20 @@ (module quote "(func (if i32.const 0 (then) (else)))") "unexpected token" ) + +(assert_malformed + (module quote "(func i32.const 1 if else else end)") + "unexpected token" +) +(assert_malformed + (module quote "(func (if (i32.const 1) (then) (else) (else)))") + "unexpected token" +) +(assert_malformed + (module quote "(func else)") + "unexpected token" +) +(assert_malformed + (module quote "(func block else end)") + "unexpected token" +) From 1e23d78f73ed300317f0379997e3f096c6bd7e8f Mon Sep 17 00:00:00 2001 From: Shen-Ta Hsieh Date: Thu, 26 Nov 2026 07:12:24 +0800 Subject: [PATCH 4/7] [test] Add cases for wrong index counts An export names exactly one index, and br_table needs at least one label. Add a case for each, in plain and folded form for br_table. --- test/core/br_table.wast | 9 +++++++++ test/core/exports.wast | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/test/core/br_table.wast b/test/core/br_table.wast index 2a5197ce14..e36b1f7420 100644 --- a/test/core/br_table.wast +++ b/test/core/br_table.wast @@ -1463,3 +1463,12 @@ )) "unknown label" ) + +(assert_malformed + (module quote "(func i32.const 0 br_table)") + "unexpected token" +) +(assert_malformed + (module quote "(func (br_table (i32.const 0)))") + "unexpected token" +) diff --git a/test/core/exports.wast b/test/core/exports.wast index f27b10a54c..1d6c6ccbe7 100644 --- a/test/core/exports.wast +++ b/test/core/exports.wast @@ -72,6 +72,11 @@ "duplicate export name" ) +(assert_malformed + (module quote "(func) (export \"a\" (func 0 0))") + "unexpected token" +) + ;; Globals From 988ec81d9a865b4b8a25d8da312704bf4abadeef Mon Sep 17 00:00:00 2001 From: Shen-Ta Hsieh Date: Thu, 26 Nov 2026 07:12:25 +0800 Subject: [PATCH 5/7] [test] Add cases for elem segments with no element list Every elem segment form needs an element list, which starts with a reference type or func. Add cases for the passive, declarative and active forms without one. --- test/core/elem.wast | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/core/elem.wast b/test/core/elem.wast index 6cf25e65fb..bfef483a7b 100644 --- a/test/core/elem.wast +++ b/test/core/elem.wast @@ -92,6 +92,23 @@ (elem (i32.const 3) $g) ) +(assert_malformed + (module quote "(elem)") + "unexpected token" +) +(assert_malformed + (module quote "(elem $e)") + "unexpected token" +) +(assert_malformed + (module quote "(elem $e declare)") + "unexpected token" +) +(assert_malformed + (module quote "(table 1 funcref) (elem (table 0) (offset (i32.const 0)))") + "unexpected token" +) + ;; Basic use From d91692dd60170819dd6fbd970645178c520edef4 Mon Sep 17 00:00:00 2001 From: Shen-Ta Hsieh Date: Thu, 26 Nov 2026 07:12:25 +0800 Subject: [PATCH 6/7] [test] Add cases for duplicate elem and data segment ids The ids of elem segments and data segments must be distinct, as for other index spaces. --- test/core/data.wast | 5 +++++ test/core/elem.wast | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/test/core/data.wast b/test/core/data.wast index fd05b5e443..e52a535996 100644 --- a/test/core/data.wast +++ b/test/core/data.wast @@ -35,6 +35,11 @@ (data $d14 "a" "" "bcd") ) +(assert_malformed + (module quote "(memory 1) (data $d \"\") (data $d \"\")") + "duplicate data segment" +) + ;; Basic use (module diff --git a/test/core/elem.wast b/test/core/elem.wast index bfef483a7b..1499ff30ef 100644 --- a/test/core/elem.wast +++ b/test/core/elem.wast @@ -108,6 +108,10 @@ (module quote "(table 1 funcref) (elem (table 0) (offset (i32.const 0)))") "unexpected token" ) +(assert_malformed + (module quote "(elem $e func) (elem $e func)") + "duplicate elem segment" +) ;; Basic use From 7d3b922fc338a4124c84f5d03cc7294700bfd404 Mon Sep 17 00:00:00 2001 From: Shen-Ta Hsieh Date: Thu, 26 Nov 2026 07:12:25 +0800 Subject: [PATCH 7/7] [test] Add cases for the operand order of v128.storeN_lane The lane index of v128.storeN_lane comes after the memarg. Add cases that put it before the memarg, with and without a memory index. The cases come from simd/meta/simd_store_lane.py. --- test/core/simd/meta/simd_store_lane.py | 21 +++++++++++++++++++++ test/core/simd/simd_store16_lane.wast | 17 +++++++++++++++++ test/core/simd/simd_store32_lane.wast | 17 +++++++++++++++++ test/core/simd/simd_store64_lane.wast | 17 +++++++++++++++++ test/core/simd/simd_store8_lane.wast | 17 +++++++++++++++++ 5 files changed, 89 insertions(+) diff --git a/test/core/simd/meta/simd_store_lane.py b/test/core/simd/meta/simd_store_lane.py index f0a8e284fe..4f8f9014ee 100644 --- a/test/core/simd/meta/simd_store_lane.py +++ b/test/core/simd/meta/simd_store_lane.py @@ -134,6 +134,27 @@ def get_invalid_cases(self): invalid_cases.append('') + invalid_cases.append(';; the lane index comes after the memarg: $mem offset=1 0') + invalid_cases.append( + '(assert_malformed\n' + ' (module quote\n' + ' "(memory $mem 1)"\n' + ' "(func (param $x v128)"\n' + ' " (v128.store{lane_len}_lane $mem 0 offset=1 (i32.const 0) (local.get $x)))"\n' + ' )\n' + ' "unexpected token")'.format(lane_len=self.LANE_LEN)) + invalid_cases.append(';; the lane index comes after the memarg: offset=1 0') + invalid_cases.append( + '(assert_malformed\n' + ' (module quote\n' + ' "(memory 1)"\n' + ' "(func (param $x v128)"\n' + ' " (v128.store{lane_len}_lane 0 offset=1 (i32.const 0) (local.get $x)))"\n' + ' )\n' + ' "unexpected token")'.format(lane_len=self.LANE_LEN)) + + invalid_cases.append('') + invalid_cases.append(';; invalid memarg alignment') invalid_cases.append( '(assert_invalid\n' diff --git a/test/core/simd/simd_store16_lane.wast b/test/core/simd/simd_store16_lane.wast index d8ea35c3fa..4956c333a7 100644 --- a/test/core/simd/simd_store16_lane.wast +++ b/test/core/simd/simd_store16_lane.wast @@ -291,6 +291,23 @@ (v128.store16_lane 8 (i32.const 0) (local.get $x)))) "invalid lane index") +;; the lane index comes after the memarg: $mem offset=1 0 +(assert_malformed + (module quote + "(memory $mem 1)" + "(func (param $x v128)" + " (v128.store16_lane $mem 0 offset=1 (i32.const 0) (local.get $x)))" + ) + "unexpected token") +;; the lane index comes after the memarg: offset=1 0 +(assert_malformed + (module quote + "(memory 1)" + "(func (param $x v128)" + " (v128.store16_lane 0 offset=1 (i32.const 0) (local.get $x)))" + ) + "unexpected token") + ;; invalid memarg alignment (assert_invalid (module (memory 1) diff --git a/test/core/simd/simd_store32_lane.wast b/test/core/simd/simd_store32_lane.wast index 847bab9e6f..4546344df3 100644 --- a/test/core/simd/simd_store32_lane.wast +++ b/test/core/simd/simd_store32_lane.wast @@ -191,6 +191,23 @@ (v128.store32_lane 4 (i32.const 0) (local.get $x)))) "invalid lane index") +;; the lane index comes after the memarg: $mem offset=1 0 +(assert_malformed + (module quote + "(memory $mem 1)" + "(func (param $x v128)" + " (v128.store32_lane $mem 0 offset=1 (i32.const 0) (local.get $x)))" + ) + "unexpected token") +;; the lane index comes after the memarg: offset=1 0 +(assert_malformed + (module quote + "(memory 1)" + "(func (param $x v128)" + " (v128.store32_lane 0 offset=1 (i32.const 0) (local.get $x)))" + ) + "unexpected token") + ;; invalid memarg alignment (assert_invalid (module (memory 1) diff --git a/test/core/simd/simd_store64_lane.wast b/test/core/simd/simd_store64_lane.wast index 2ed1dcd689..4ef09084a0 100644 --- a/test/core/simd/simd_store64_lane.wast +++ b/test/core/simd/simd_store64_lane.wast @@ -123,6 +123,23 @@ (v128.store64_lane 2 (i32.const 0) (local.get $x)))) "invalid lane index") +;; the lane index comes after the memarg: $mem offset=1 0 +(assert_malformed + (module quote + "(memory $mem 1)" + "(func (param $x v128)" + " (v128.store64_lane $mem 0 offset=1 (i32.const 0) (local.get $x)))" + ) + "unexpected token") +;; the lane index comes after the memarg: offset=1 0 +(assert_malformed + (module quote + "(memory 1)" + "(func (param $x v128)" + " (v128.store64_lane 0 offset=1 (i32.const 0) (local.get $x)))" + ) + "unexpected token") + ;; invalid memarg alignment (assert_invalid (module (memory 1) diff --git a/test/core/simd/simd_store8_lane.wast b/test/core/simd/simd_store8_lane.wast index b4e4a583f1..d3016182f3 100644 --- a/test/core/simd/simd_store8_lane.wast +++ b/test/core/simd/simd_store8_lane.wast @@ -419,6 +419,23 @@ (v128.store8_lane 16 (i32.const 0) (local.get $x)))) "invalid lane index") +;; the lane index comes after the memarg: $mem offset=1 0 +(assert_malformed + (module quote + "(memory $mem 1)" + "(func (param $x v128)" + " (v128.store8_lane $mem 0 offset=1 (i32.const 0) (local.get $x)))" + ) + "unexpected token") +;; the lane index comes after the memarg: offset=1 0 +(assert_malformed + (module quote + "(memory 1)" + "(func (param $x v128)" + " (v128.store8_lane 0 offset=1 (i32.const 0) (local.get $x)))" + ) + "unexpected token") + ;; invalid memarg alignment (assert_invalid (module (memory 1)