summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaiju Tsuiki <tzik@users.noreply.github.com>2016-10-15 01:57:17 +0900
committerAlon Zakai <alonzakai@gmail.com>2016-10-14 09:57:17 -0700
commit392995b646d2f5f36bf3110eac149892ebda74df (patch)
tree2c278abcd4005bb3f4450407b9b1638b512511dc
parent89844da32a940042f0fcd61506e5c422e82c7536 (diff)
downloadbinaryen-392995b646d2f5f36bf3110eac149892ebda74df.tar.gz
binaryen-392995b646d2f5f36bf3110eac149892ebda74df.tar.bz2
binaryen-392995b646d2f5f36bf3110eac149892ebda74df.zip
Do not use exported memory as a root set of RemoveUnusedFunctions pass (#763)
* Do not use exported memory as a root set of RemoveUnusedFunctions pass RemoveUnusedFunctions pass of wasm-opt fails when the memory is exported. That's due to a wrong root set handling on the exported symbols. This CL fixes the failure by ignoring non-function exported symbol.
-rw-r--r--src/passes/RemoveUnusedFunctions.cpp4
-rw-r--r--test/passes/remove-unused-functions.txt1
-rw-r--r--test/passes/remove-unused-functions.wast1
3 files changed, 5 insertions, 1 deletions
diff --git a/src/passes/RemoveUnusedFunctions.cpp b/src/passes/RemoveUnusedFunctions.cpp
index 78b0f0ffc..ec9e271b7 100644
--- a/src/passes/RemoveUnusedFunctions.cpp
+++ b/src/passes/RemoveUnusedFunctions.cpp
@@ -36,7 +36,9 @@ struct RemoveUnusedFunctions : public Pass {
}
// Exports are roots.
for (auto& curr : module->exports) {
- root.push_back(module->getFunction(curr->value));
+ if (curr->kind == ExternalKind::Function) {
+ root.push_back(module->getFunction(curr->value));
+ }
}
// For now, all functions that can be called indirectly are marked as roots.
for (auto& segment : module->table.segments) {
diff --git a/test/passes/remove-unused-functions.txt b/test/passes/remove-unused-functions.txt
index 0e3cef1b9..6e4a452b3 100644
--- a/test/passes/remove-unused-functions.txt
+++ b/test/passes/remove-unused-functions.txt
@@ -3,6 +3,7 @@
(table 1 1 anyfunc)
(elem (i32.const 0) $called_indirect)
(memory $0 0)
+ (export "memory" (memory $0))
(export "exported" (func $exported))
(start $start)
(func $start (type $0)
diff --git a/test/passes/remove-unused-functions.wast b/test/passes/remove-unused-functions.wast
index 19b72f2ac..c3d25d021 100644
--- a/test/passes/remove-unused-functions.wast
+++ b/test/passes/remove-unused-functions.wast
@@ -2,6 +2,7 @@
(memory 0)
(start $start)
(type $0 (func))
+ (export "memory" (memory $0))
(export "exported" $exported)
(table 1 1 anyfunc)
(elem (i32.const 0) $called_indirect)