summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)