diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2020-12-17 22:35:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-17 19:35:16 -0800 |
commit | ae16f5cb995e3756ccb2093749bc5595fd86a2df (patch) | |
tree | 069128aa05216685bb7866de4a90a84c3b68bfa5 /test | |
parent | cad723a3827913f53ecfa7189b011be389d28ae7 (diff) | |
download | binaryen-ae16f5cb995e3756ccb2093749bc5595fd86a2df.tar.gz binaryen-ae16f5cb995e3756ccb2093749bc5595fd86a2df.tar.bz2 binaryen-ae16f5cb995e3756ccb2093749bc5595fd86a2df.zip |
[module-splitting] Fix a crash when a function is exported twice (#3455)
`ModuleSplitter::thunkExportedSecondaryFunctions` creates a thunk for each
secondary function that needs to be exported from the main module. Previously,
if a secondary function was exported twice, this code would try to create two
thunks for it rather than just making one thunk and exporting it twice. This
caused a fatal error because the second thunk had the same name as the first
thunk and therefore could not be added to the module. This PR fixes the issue by
creating no more than one thunk per function.
Diffstat (limited to 'test')
-rw-r--r-- | test/example/module-splitting.cpp | 8 | ||||
-rw-r--r-- | test/example/module-splitting.txt | 36 |
2 files changed, 44 insertions, 0 deletions
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) + ) +) + + |