summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm/wasm-binary.cpp2
-rw-r--r--test/unit/input/only-imported-memory.wasmbin0 -> 50 bytes
-rw-r--r--test/unit/test_only_imported_memory.py8
-rw-r--r--test/unit/utils.py6
4 files changed, 13 insertions, 3 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 364942a56..5d21f5130 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -204,7 +204,7 @@ void WasmBinaryWriter::writeStart() {
}
void WasmBinaryWriter::writeMemories() {
- if (wasm->memories.empty()) {
+ if (importInfo->getNumDefinedMemories() == 0) {
return;
}
BYN_TRACE("== writeMemories\n");
diff --git a/test/unit/input/only-imported-memory.wasm b/test/unit/input/only-imported-memory.wasm
new file mode 100644
index 000000000..175113e10
--- /dev/null
+++ b/test/unit/input/only-imported-memory.wasm
Binary files differ
diff --git a/test/unit/test_only_imported_memory.py b/test/unit/test_only_imported_memory.py
new file mode 100644
index 000000000..427f464d0
--- /dev/null
+++ b/test/unit/test_only_imported_memory.py
@@ -0,0 +1,8 @@
+from . import utils
+
+
+class OnlyImportedMemoryTest(utils.BinaryenTestCase):
+ def test_only_imported_memory(self):
+ # We should not create a memories section for a file with only an
+ # imported memory: such a module has no declared memories.
+ self.roundtrip('only-imported-memory.wasm', debug=False)
diff --git a/test/unit/utils.py b/test/unit/utils.py
index b75ed311c..b0391afad 100644
--- a/test/unit/utils.py
+++ b/test/unit/utils.py
@@ -9,9 +9,11 @@ class BinaryenTestCase(unittest.TestCase):
return os.path.join(shared.options.binaryen_test, 'unit', 'input',
filename)
- def roundtrip(self, filename, opts=[]):
+ def roundtrip(self, filename, opts=[], debug=True):
+ if debug:
+ opts = opts + ['-g']
path = self.input_path(filename)
- p = shared.run_process(shared.WASM_OPT + ['-g', '-o', 'a.wasm', path] +
+ p = shared.run_process(shared.WASM_OPT + ['-o', 'a.wasm', path] +
opts)
self.assertEqual(p.returncode, 0)
with open(path, 'rb') as f: