summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2019-12-17 13:55:01 -0800
committerGitHub <noreply@github.com>2019-12-17 13:55:01 -0800
commit323e475a3ab57fe4ffd0b5826af5f6cbf0061265 (patch)
treeec8a06b85eeadc4a3ec4a66fcd6a1950b7569b2d
parentf0a2e2c75c7bb3008f10b6edbb8dc4cfd27b7d28 (diff)
downloadbinaryen-323e475a3ab57fe4ffd0b5826af5f6cbf0061265.tar.gz
binaryen-323e475a3ab57fe4ffd0b5826af5f6cbf0061265.tar.bz2
binaryen-323e475a3ab57fe4ffd0b5826af5f6cbf0061265.zip
Correctly clear memory / table info in clearModule (#2536)
Currently `ModuleUtils::clearModule` does not clear `exists` flags in the memory and table, and running RoundTrip pass on any module that has a memory or a table fails as a result. This creates `clear` function in `Memory` and `Table` and makes `clearModule` call them.
-rw-r--r--src/ir/module-utils.h4
-rw-r--r--src/wasm.h15
-rw-r--r--test/passes/roundtrip.txt4
-rw-r--r--test/passes/roundtrip.wast5
4 files changed, 26 insertions, 2 deletions
diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h
index d84648dfd..014fcb34c 100644
--- a/src/ir/module-utils.h
+++ b/src/ir/module-utils.h
@@ -135,8 +135,8 @@ inline void clearModule(Module& wasm) {
wasm.functions.clear();
wasm.globals.clear();
wasm.events.clear();
- wasm.table.segments.clear();
- wasm.memory.segments.clear();
+ wasm.table.clear();
+ wasm.memory.clear();
wasm.start = Name();
wasm.userSections.clear();
wasm.debugInfoFileNames.clear();
diff --git a/src/wasm.h b/src/wasm.h
index cc2070eb2..0ed4f27bd 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -1241,6 +1241,13 @@ public:
Table() { name = Name::fromInt(0); }
bool hasMax() { return max != kUnlimitedSize; }
+ void clear() {
+ exists = false;
+ name = "";
+ initial = 0;
+ max = kMaxSize;
+ segments.clear();
+ }
};
class Memory : public Importable {
@@ -1284,6 +1291,14 @@ public:
Memory() { name = Name::fromInt(0); }
bool hasMax() { return max != kUnlimitedSize; }
+ void clear() {
+ exists = false;
+ name = "";
+ initial = 0;
+ max = kMaxSize;
+ segments.clear();
+ shared = false;
+ }
};
class Global : public Importable {
diff --git a/test/passes/roundtrip.txt b/test/passes/roundtrip.txt
index bcd8b186a..fa1c44984 100644
--- a/test/passes/roundtrip.txt
+++ b/test/passes/roundtrip.txt
@@ -5,3 +5,7 @@
(unreachable)
)
)
+(module
+ (memory $ 1 1)
+ (table $ 0 funcref)
+)
diff --git a/test/passes/roundtrip.wast b/test/passes/roundtrip.wast
index f562ba779..7d1eb174b 100644
--- a/test/passes/roundtrip.wast
+++ b/test/passes/roundtrip.wast
@@ -9,3 +9,8 @@
(nop)
)
)
+
+(module
+ (memory 1 1)
+ (table 0 funcref)
+)