Skip to content

Commit 323e475

Browse files
authored
Correctly clear memory / table info in clearModule (WebAssembly#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.
1 parent f0a2e2c commit 323e475

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/ir/module-utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ inline void clearModule(Module& wasm) {
135135
wasm.functions.clear();
136136
wasm.globals.clear();
137137
wasm.events.clear();
138-
wasm.table.segments.clear();
139-
wasm.memory.segments.clear();
138+
wasm.table.clear();
139+
wasm.memory.clear();
140140
wasm.start = Name();
141141
wasm.userSections.clear();
142142
wasm.debugInfoFileNames.clear();

src/wasm.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,13 @@ class Table : public Importable {
12411241

12421242
Table() { name = Name::fromInt(0); }
12431243
bool hasMax() { return max != kUnlimitedSize; }
1244+
void clear() {
1245+
exists = false;
1246+
name = "";
1247+
initial = 0;
1248+
max = kMaxSize;
1249+
segments.clear();
1250+
}
12441251
};
12451252

12461253
class Memory : public Importable {
@@ -1284,6 +1291,14 @@ class Memory : public Importable {
12841291

12851292
Memory() { name = Name::fromInt(0); }
12861293
bool hasMax() { return max != kUnlimitedSize; }
1294+
void clear() {
1295+
exists = false;
1296+
name = "";
1297+
initial = 0;
1298+
max = kMaxSize;
1299+
segments.clear();
1300+
shared = false;
1301+
}
12871302
};
12881303

12891304
class Global : public Importable {

test/passes/roundtrip.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
(unreachable)
66
)
77
)
8+
(module
9+
(memory $ 1 1)
10+
(table $ 0 funcref)
11+
)

test/passes/roundtrip.wast

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@
99
(nop)
1010
)
1111
)
12+
13+
(module
14+
(memory 1 1)
15+
(table 0 funcref)
16+
)

0 commit comments

Comments
 (0)