From 73d10ea90c35a18bc48b68bfc4d908b648d288cb Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 17 Oct 2022 09:56:05 -0700 Subject: [PATCH 1/3] fix --- src/wasm/wasm-binary.cpp | 2 +- test/unit/input/only-imported-memory.wasm | Bin 0 -> 50 bytes test/unit/test_only_imported_memory.py | 9 +++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/unit/input/only-imported-memory.wasm create mode 100644 test/unit/test_only_imported_memory.py diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 364942a5620..5d21f513047 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 0000000000000000000000000000000000000000..175113e10f2c0b054ac808a40d965e55888dbeb0 GIT binary patch literal 50 zcmV~$yAgmO6ac}yhYlYbu?;&BW(^v^A&LS#xII?M?eb6#ce%vL91r2b_T}} Dm$e0P literal 0 HcmV?d00001 diff --git a/test/unit/test_only_imported_memory.py b/test/unit/test_only_imported_memory.py new file mode 100644 index 00000000000..f26d97d6ce5 --- /dev/null +++ b/test/unit/test_only_imported_memory.py @@ -0,0 +1,9 @@ +from scripts.test import shared +from . import utils + + +class DataCountTest(utils.BinaryenTestCase): + def test_datacount(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') From 87594ee03effdef6e4506ca4adc790336584476a Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 17 Oct 2022 09:58:23 -0700 Subject: [PATCH 2/3] fix --- test/unit/test_only_imported_memory.py | 6 +++--- test/unit/utils.py | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/unit/test_only_imported_memory.py b/test/unit/test_only_imported_memory.py index f26d97d6ce5..227ccfbfd08 100644 --- a/test/unit/test_only_imported_memory.py +++ b/test/unit/test_only_imported_memory.py @@ -2,8 +2,8 @@ from . import utils -class DataCountTest(utils.BinaryenTestCase): - def test_datacount(self): +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') + self.roundtrip('only-imported-memory.wasm', debug=False) diff --git a/test/unit/utils.py b/test/unit/utils.py index b75ed311c94..b0391afadf9 100644 --- a/test/unit/utils.py +++ b/test/unit/utils.py @@ -9,9 +9,11 @@ def input_path(self, filename): 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: From 38fa2b7ce74b05785c3986923a402f5b5e804b8b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 17 Oct 2022 13:17:14 -0700 Subject: [PATCH 3/3] lint --- test/unit/test_only_imported_memory.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/test_only_imported_memory.py b/test/unit/test_only_imported_memory.py index 227ccfbfd08..427f464d09f 100644 --- a/test/unit/test_only_imported_memory.py +++ b/test/unit/test_only_imported_memory.py @@ -1,4 +1,3 @@ -from scripts.test import shared from . import utils