summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-03-29 15:32:01 -0700
committerGitHub <noreply@github.com>2021-03-29 15:32:01 -0700
commit09cba0fa50b0492ecf7b7886180dbd6c5aa5d04d (patch)
treebc654bcc92cab64a08fe0bd9197c2f9c4a324ca4 /test
parent244f886cb2f1d9c5dddbf2dea5d47e6b0a434c5d (diff)
downloadbinaryen-09cba0fa50b0492ecf7b7886180dbd6c5aa5d04d.tar.gz
binaryen-09cba0fa50b0492ecf7b7886180dbd6c5aa5d04d.tar.bz2
binaryen-09cba0fa50b0492ecf7b7886180dbd6c5aa5d04d.zip
Scan module-level code in necessary places (#3744)
Several old passes like DeadArgumentElimination and DuplicateFunctionElimination need to look at all ref.funcs, and they scanned functions for that, but that is not enough as such an instruction might appear in a global initializer. To fix this, add a walkModuleCode method. walkModuleCode is useful when doing the pattern of creating a function-parallel pass to scan functions quickly, but we also want to do the same scanning of code at the module level. This allows doing so in a single line. (It is also possible to just do walk() on the entire module, which will find all code, but that is not function-parallel. Perhaps we should have a walkParallel() option to simplify this further in a followup, and that would call walkModuleCode afterwards etc.) Also add some missing validation and comments in the validator about issues that I noticed in relation to the new testcases here.
Diffstat (limited to 'test')
-rw-r--r--test/example/c-api-kitchen-sink.c6
-rw-r--r--test/passes/dae_all-features.txt20
-rw-r--r--test/passes/dae_all-features.wast21
-rw-r--r--test/passes/duplicate-function-elimination_all-features.txt13
-rw-r--r--test/passes/duplicate-function-elimination_all-features.wast18
5 files changed, 75 insertions, 3 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c
index 9e6366d36..aa82723b4 100644
--- a/test/example/c-api-kitchen-sink.c
+++ b/test/example/c-api-kitchen-sink.c
@@ -893,12 +893,12 @@ void test_core() {
BinaryenModuleSetFeatures(module, features);
assert(BinaryenModuleGetFeatures(module) == features);
- // Verify it validates
- assert(BinaryenModuleValidate(module));
-
// Print it out
BinaryenModulePrint(module);
+ // Verify it validates
+ assert(BinaryenModuleValidate(module));
+
// Clean up the module, which owns all the objects we created above
BinaryenModuleDispose(module);
}
diff --git a/test/passes/dae_all-features.txt b/test/passes/dae_all-features.txt
index 4ca21576f..ea439bc9e 100644
--- a/test/passes/dae_all-features.txt
+++ b/test/passes/dae_all-features.txt
@@ -292,3 +292,23 @@
(ref.func $0)
)
)
+(module
+ (type $none_=>_none (func))
+ (type $i64 (func (param i64)))
+ (global $global$0 (ref $i64) (ref.func $0))
+ (export "even" (func $1))
+ (func $0 (param $0 i64)
+ (unreachable)
+ )
+ (func $1
+ (call_ref
+ (i64.const 0)
+ (global.get $global$0)
+ )
+ )
+ (func $2
+ (call $0
+ (i64.const 0)
+ )
+ )
+)
diff --git a/test/passes/dae_all-features.wast b/test/passes/dae_all-features.wast
index 097c144cc..55e935f3b 100644
--- a/test/passes/dae_all-features.wast
+++ b/test/passes/dae_all-features.wast
@@ -172,3 +172,24 @@
(ref.func $0)
)
)
+(module
+ (type $i64 (func (param i64)))
+ (global $global$0 (ref $i64) (ref.func $0))
+ (export "even" (func $1))
+ ;; the argument to this function cannot be removed due to the ref.func of it
+ ;; in a global
+ (func $0 (param $0 i64)
+ (unreachable)
+ )
+ (func $1
+ (call_ref
+ (i64.const 0)
+ (global.get $global$0)
+ )
+ )
+ (func $2
+ (call $0
+ (i64.const 0)
+ )
+ )
+)
diff --git a/test/passes/duplicate-function-elimination_all-features.txt b/test/passes/duplicate-function-elimination_all-features.txt
index a7a751f76..6dd5a1004 100644
--- a/test/passes/duplicate-function-elimination_all-features.txt
+++ b/test/passes/duplicate-function-elimination_all-features.txt
@@ -19,3 +19,16 @@
(nop)
)
)
+(module
+ (type $func (func (result i32)))
+ (global $global$0 (ref $func) (ref.func $foo))
+ (export "export" (func $2))
+ (func $foo (result i32)
+ (unreachable)
+ )
+ (func $2 (result i32)
+ (call_ref
+ (global.get $global$0)
+ )
+ )
+)
diff --git a/test/passes/duplicate-function-elimination_all-features.wast b/test/passes/duplicate-function-elimination_all-features.wast
index 116542c96..1d04e878c 100644
--- a/test/passes/duplicate-function-elimination_all-features.wast
+++ b/test/passes/duplicate-function-elimination_all-features.wast
@@ -21,3 +21,21 @@
(func $foo ;; happens to share a name with the memory
)
)
+;; renaming after deduplication must update ref.funcs in globals
+(module
+ (type $func (func (result i32)))
+ (global $global$0 (ref $func) (ref.func $bar))
+ ;; These two identical functions can be merged. The ref.func in the global must
+ ;; be updated accordingly.
+ (func $foo (result i32)
+ (unreachable)
+ )
+ (func $bar (result i32)
+ (unreachable)
+ )
+ (func "export" (result i32)
+ (call_ref
+ (global.get $global$0)
+ )
+ )
+)