summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/module-splitting.cpp4
-rw-r--r--test/example/module-splitting.cpp8
-rw-r--r--test/example/module-splitting.txt36
3 files changed, 48 insertions, 0 deletions
diff --git a/src/ir/module-splitting.cpp b/src/ir/module-splitting.cpp
index f4f00c9af..1f33b44ac 100644
--- a/src/ir/module-splitting.cpp
+++ b/src/ir/module-splitting.cpp
@@ -345,6 +345,10 @@ void ModuleSplitter::thunkExportedSecondaryFunctions() {
continue;
}
Name secondaryFunc = ex->value;
+ if (primary.getFunctionOrNull(secondaryFunc)) {
+ // We've already created a thunk for this function
+ continue;
+ }
auto tableSlot = tableManager.getSlot(secondaryFunc);
auto func = std::make_unique<Function>();
diff --git a/test/example/module-splitting.cpp b/test/example/module-splitting.cpp
index ad0da84a8..ab42ff5fd 100644
--- a/test/example/module-splitting.cpp
+++ b/test/example/module-splitting.cpp
@@ -386,4 +386,12 @@ int main() {
(call $foo (i32.const 1))
)
))");
+
+ // Multiple exports of a secondary function
+ do_test({}, R"(
+ (module
+ (export "foo1" (func $foo))
+ (export "foo2" (func $foo))
+ (func $foo)
+ ))");
}
diff --git a/test/example/module-splitting.txt b/test/example/module-splitting.txt
index 9b28f31ca..32d579c2c 100644
--- a/test/example/module-splitting.txt
+++ b/test/example/module-splitting.txt
@@ -943,3 +943,39 @@ Secondary:
)
+Before:
+(module
+ (type $none_=>_none (func))
+ (export "foo1" (func $foo))
+ (export "foo2" (func $foo))
+ (func $foo
+ (nop)
+ )
+)
+Keeping: <none>
+After:
+(module
+ (type $none_=>_none (func))
+ (import "placeholder" "0" (func $placeholder_0))
+ (table $0 1 funcref)
+ (elem (i32.const 0) $placeholder_0)
+ (export "foo1" (func $foo))
+ (export "foo2" (func $foo))
+ (export "%table" (table $0))
+ (func $foo
+ (call_indirect (type $none_=>_none)
+ (i32.const 0)
+ )
+ )
+)
+Secondary:
+(module
+ (type $none_=>_none (func))
+ (import "primary" "%table" (table $0 1 funcref))
+ (elem (i32.const 0) $foo)
+ (func $foo
+ (nop)
+ )
+)
+
+