From b12a089621ec4e45f9c5d8e827c26f9263f14c6d Mon Sep 17 00:00:00 2001 From: Eduardo-Gv17 Date: Sun, 8 Nov 2026 10:57:37 -0500 Subject: [PATCH] Migrate three legacy pass tests to lit --- .../passes/duplicate-import-elimination.wast | 42 ++++++++++++++ .../remove-unused-names_precompute.wast | 57 +++++++++++++++++++ test/lit/passes/set-globals.wast | 15 +++++ test/passes/duplicate-import-elimination.txt | 17 ------ test/passes/duplicate-import-elimination.wast | 13 ----- .../passes/remove-unused-names_precompute.txt | 25 -------- .../remove-unused-names_precompute.wast | 28 --------- test/passes/set-globals.passes | 1 - test/passes/set-globals.txt | 4 -- test/passes/set-globals.wast | 7 --- 10 files changed, 114 insertions(+), 95 deletions(-) create mode 100644 test/lit/passes/duplicate-import-elimination.wast create mode 100644 test/lit/passes/remove-unused-names_precompute.wast create mode 100644 test/lit/passes/set-globals.wast delete mode 100644 test/passes/duplicate-import-elimination.txt delete mode 100644 test/passes/duplicate-import-elimination.wast delete mode 100644 test/passes/remove-unused-names_precompute.txt delete mode 100644 test/passes/remove-unused-names_precompute.wast delete mode 100644 test/passes/set-globals.passes delete mode 100644 test/passes/set-globals.txt delete mode 100644 test/passes/set-globals.wast diff --git a/test/lit/passes/duplicate-import-elimination.wast b/test/lit/passes/duplicate-import-elimination.wast new file mode 100644 index 00000000000..3ae35cb34ca --- /dev/null +++ b/test/lit/passes/duplicate-import-elimination.wast @@ -0,0 +1,42 @@ +;; RUN: foreach %s %t wasm-opt --duplicate-import-elimination -S -o - | filecheck %s + +;; Merge imports with matching signatures and update calls, elements, and start. +;; The import with a different signature must remain distinct. + +(module + ;; CHECK: (type $0 (func)) + + ;; CHECK: (type $1 (func (param i32))) + ;; CHECK-NOT: (import "env" "waka" (func $bar + + ;; CHECK: (import "env" "waka" (func $foo)) + ;; CHECK-NOT: (import "env" "waka" (func $bar + (import "env" "waka" (func $foo)) + (import "env" "waka" (func $bar)) + ;; CHECK: (import "env" "waka" (func $wrong (param i32))) + ;; CHECK-NOT: (import "env" "waka" (func $bar + (import "env" "waka" (func $wrong (param i32))) + (table 2 2 funcref) + (elem (i32.const 0) $foo $bar) + (start $bar) + ;; CHECK: (table $0 2 2 funcref) + + ;; CHECK: (elem $0 (i32.const 0) $foo $foo) + + ;; CHECK: (export "baz" (func $baz)) + + ;; CHECK: (start $foo) + + ;; CHECK: (func $baz + ;; CHECK-NEXT: (call $foo) + ;; CHECK-NEXT: (call $foo) + ;; CHECK-NEXT: (call $wrong + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $baz (export "baz") + (call $foo) + (call $bar) + (call $wrong (i32.const 1)) + ) +) diff --git a/test/lit/passes/remove-unused-names_precompute.wast b/test/lit/passes/remove-unused-names_precompute.wast new file mode 100644 index 00000000000..cd2a3312cff --- /dev/null +++ b/test/lit/passes/remove-unused-names_precompute.wast @@ -0,0 +1,57 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. +;; RUN: foreach %s %t wasm-opt --remove-unused-names --precompute -S -o - | filecheck %s + +;; Preserve the interaction between name removal and a constant br_table target. + +(module + ;; CHECK: (type $0 (func (param i32))) + + ;; CHECK: (memory $0 256 256) + (memory $0 256 256) + ;; CHECK: (func $__ZN10WasmAssertC2Ev__async_cb (param $$0 i32) + ;; CHECK-NEXT: (block $switch-default + ;; CHECK-NEXT: (nop) + ;; CHECK-NEXT: (block + ;; CHECK-NEXT: (i32.store + ;; CHECK-NEXT: (i32.const 12) + ;; CHECK-NEXT: (i32.const 26) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (return) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (block + ;; CHECK-NEXT: (local.set $$0 + ;; CHECK-NEXT: (i32.const 4) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (i32.store + ;; CHECK-NEXT: (local.get $$0) + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $__ZN10WasmAssertC2Ev__async_cb (param $$0 i32) + (block $switch-default + (block $switch-case + (br_table $switch-case $switch-default + (i32.const 0) + ) + ) + (block + (i32.store + (i32.const 12) + (i32.const 26) + ) + (return) + ) + ) + (block + (local.set $$0 + (i32.const 4) + ) + (i32.store + (local.get $$0) + (i32.const 1) + ) + ) + ) +) diff --git a/test/lit/passes/set-globals.wast b/test/lit/passes/set-globals.wast new file mode 100644 index 00000000000..a88249b2c4c --- /dev/null +++ b/test/lit/passes/set-globals.wast @@ -0,0 +1,15 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. +;; RUN: foreach %s %t wasm-opt --set-globals --pass-arg=set-globals@foo=1337,bar=42 -S -o - | filecheck %s + +;; Set both an imported i32 global and a defined i64 global using pass arguments. + +(module + ;; an imported i32 + (import "env" "in" (global $foo i32)) + + ;; a defined i64 + ;; CHECK: (global $foo i32 (i32.const 1337)) + + ;; CHECK: (global $bar i64 (i64.const 42)) + (global $bar i64 (i64.const 1234)) +) diff --git a/test/passes/duplicate-import-elimination.txt b/test/passes/duplicate-import-elimination.txt deleted file mode 100644 index 4ea4c164433..00000000000 --- a/test/passes/duplicate-import-elimination.txt +++ /dev/null @@ -1,17 +0,0 @@ -(module - (type $0 (func)) - (type $1 (func (param i32))) - (import "env" "waka" (func $foo)) - (import "env" "waka" (func $wrong (param i32))) - (table $0 2 2 funcref) - (elem $0 (i32.const 0) $foo $foo) - (export "baz" (func $baz)) - (start $foo) - (func $baz - (call $foo) - (call $foo) - (call $wrong - (i32.const 1) - ) - ) -) diff --git a/test/passes/duplicate-import-elimination.wast b/test/passes/duplicate-import-elimination.wast deleted file mode 100644 index a6f9846745e..00000000000 --- a/test/passes/duplicate-import-elimination.wast +++ /dev/null @@ -1,13 +0,0 @@ -(module - (import "env" "waka" (func $foo)) - (import "env" "waka" (func $bar)) - (import "env" "waka" (func $wrong (param i32))) - (table 2 2 funcref) - (elem (i32.const 0) $foo $bar) - (start $bar) - (func $baz (export "baz") - (call $foo) - (call $bar) - (call $wrong (i32.const 1)) - ) -) diff --git a/test/passes/remove-unused-names_precompute.txt b/test/passes/remove-unused-names_precompute.txt deleted file mode 100644 index d458991ac24..00000000000 --- a/test/passes/remove-unused-names_precompute.txt +++ /dev/null @@ -1,25 +0,0 @@ -(module - (type $0 (func (param i32))) - (memory $0 256 256) - (func $__ZN10WasmAssertC2Ev__async_cb (param $$0 i32) - (block $switch-default - (nop) - (block - (i32.store - (i32.const 12) - (i32.const 26) - ) - (return) - ) - ) - (block - (local.set $$0 - (i32.const 4) - ) - (i32.store - (local.get $$0) - (i32.const 1) - ) - ) - ) -) diff --git a/test/passes/remove-unused-names_precompute.wast b/test/passes/remove-unused-names_precompute.wast deleted file mode 100644 index cc3dbfea7bd..00000000000 --- a/test/passes/remove-unused-names_precompute.wast +++ /dev/null @@ -1,28 +0,0 @@ -(module - (memory $0 256 256) - (func $__ZN10WasmAssertC2Ev__async_cb (param $$0 i32) - (block $switch-default - (block $switch-case - (br_table $switch-case $switch-default - (i32.const 0) - ) - ) - (block - (i32.store - (i32.const 12) - (i32.const 26) - ) - (return) - ) - ) - (block - (local.set $$0 - (i32.const 4) - ) - (i32.store - (local.get $$0) - (i32.const 1) - ) - ) - ) -) diff --git a/test/passes/set-globals.passes b/test/passes/set-globals.passes deleted file mode 100644 index 9f01c13a623..00000000000 --- a/test/passes/set-globals.passes +++ /dev/null @@ -1 +0,0 @@ -set-globals_pass-arg=set-globals@foo=1337,bar=42 diff --git a/test/passes/set-globals.txt b/test/passes/set-globals.txt deleted file mode 100644 index 354f133c151..00000000000 --- a/test/passes/set-globals.txt +++ /dev/null @@ -1,4 +0,0 @@ -(module - (global $foo i32 (i32.const 1337)) - (global $bar i64 (i64.const 42)) -) diff --git a/test/passes/set-globals.wast b/test/passes/set-globals.wast deleted file mode 100644 index 4af112883e1..00000000000 --- a/test/passes/set-globals.wast +++ /dev/null @@ -1,7 +0,0 @@ -(module - ;; an imported i32 - (import "env" "in" (global $foo i32)) - - ;; a defined i64 - (global $bar i64 (i64.const 1234)) -)