summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Wirtz <dcode@dcode.io>2020-09-02 21:57:04 +0200
committerGitHub <noreply@github.com>2020-09-02 21:57:04 +0200
commit7c1253ee4513ec86e851536e29fd5f11d13b0b19 (patch)
tree1d71d5d46f8c48eb7c9e1ad31efd8239292fed1d /src
parent7438b6cbcb9b194db59c0e5c497208ce57c964a9 (diff)
downloadbinaryen-7c1253ee4513ec86e851536e29fd5f11d13b0b19.tar.gz
binaryen-7c1253ee4513ec86e851536e29fd5f11d13b0b19.tar.bz2
binaryen-7c1253ee4513ec86e851536e29fd5f11d13b0b19.zip
Fix LegalizeJSInterface leaking duplicate stub Functions (#3095)
Fixes `LegalizeJSInterface::makeLegalStub` forgetting to `delete` stub Functions that turned out to be not needed. Now checks whether a stub is needed and otherwise skips creating the redundant stub right away.
Diffstat (limited to 'src')
-rw-r--r--src/passes/LegalizeJSInterface.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp
index 7991d7eb3..2f3e484ad 100644
--- a/src/passes/LegalizeJSInterface.cpp
+++ b/src/passes/LegalizeJSInterface.cpp
@@ -214,9 +214,16 @@ private:
// JS calls the export, so it must call a legal stub that calls the actual
// wasm function
Name makeLegalStub(Function* func, Module* module) {
+ Name legalName(std::string("legalstub$") + func->name.str);
+
+ // a method may be exported multiple times
+ if (module->getFunctionOrNull(legalName)) {
+ return legalName;
+ }
+
Builder builder(*module);
auto* legal = new Function();
- legal->name = Name(std::string("legalstub$") + func->name.str);
+ legal->name = legalName;
auto* call = module->allocator.alloc<Call>();
call->target = func->name;
@@ -254,11 +261,7 @@ private:
legal->body = call;
}
- // a method may be exported multiple times
- if (!module->getFunctionOrNull(legal->name)) {
- module->addFunction(legal);
- }
- return legal->name;
+ return module->addFunction(legal)->name;
}
// wasm calls the import, so it must call a stub that calls the actual legal