diff options
author | Alon Zakai <azakai@google.com> | 2021-07-30 09:59:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-30 09:59:52 -0700 |
commit | 57138f8cf94f0a55b615be9802ce76f6a6858f22 (patch) | |
tree | aecc99dcdf8679c15d3a9c20417c9a5af2fc5be7 | |
parent | 30ff262c916933a852805fe4acf07e5d7f34891c (diff) | |
download | binaryen-57138f8cf94f0a55b615be9802ce76f6a6858f22.tar.gz binaryen-57138f8cf94f0a55b615be9802ce76f6a6858f22.tar.bz2 binaryen-57138f8cf94f0a55b615be9802ce76f6a6858f22.zip |
Do not crash in ExtractFunction if an export already exists (#4040)
We just cleared the list of exports, but the exportMap was still populated, so
the data was in an inconsistent state.
This fixes the case of running --extract-function multiple times on a file (which
is usually not useful, unless one of the passes you are debugging adds new
functions to the file - which some do).
-rw-r--r-- | src/passes/ExtractFunction.cpp | 1 | ||||
-rw-r--r-- | test/lit/passes/extract-function.wast | 2 |
2 files changed, 3 insertions, 0 deletions
diff --git a/src/passes/ExtractFunction.cpp b/src/passes/ExtractFunction.cpp index a219000c8..0c0c1477e 100644 --- a/src/passes/ExtractFunction.cpp +++ b/src/passes/ExtractFunction.cpp @@ -46,6 +46,7 @@ static void extract(PassRunner* runner, Module* module, Name name) { // Leave just one export, for the thing we want. module->exports.clear(); + module->updateMaps(); module->addExport(Builder::makeExport(name, name, ExternalKind::Function)); // Remove unneeded things. diff --git a/test/lit/passes/extract-function.wast b/test/lit/passes/extract-function.wast index 606fd326c..f53dda982 100644 --- a/test/lit/passes/extract-function.wast +++ b/test/lit/passes/extract-function.wast @@ -68,7 +68,9 @@ ;; CHECK: (elem $0 (i32.const 0) $other) (elem $0 (table $t) (i32.const 0) func $other) + ;; Test that an existing export does not cause us to crash. ;; CHECK: (export "foo" (func $foo)) + (export "foo" (func $foo)) ;; CHECK: (func $foo ;; CHECK-NEXT: (call_indirect (type $none) |