diff options
author | Alon Zakai <azakai@google.com> | 2021-01-15 21:48:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-15 13:48:29 -0800 |
commit | 2488b523216600b4de2fe1e33ad695b337f8b9f8 (patch) | |
tree | 2b421722cf4178e5979738e177cf53fbdf1c3db4 | |
parent | c57dd1ff777b04650e4603a043644a2519019665 (diff) | |
download | binaryen-2488b523216600b4de2fe1e33ad695b337f8b9f8.tar.gz binaryen-2488b523216600b4de2fe1e33ad695b337f8b9f8.tar.bz2 binaryen-2488b523216600b4de2fe1e33ad695b337f8b9f8.zip |
wasm-reduce: Fix setting of feature flags after loading (#3493)
We mistakenly did not set the flags to all, which meant that if the
features section was not present, we'd not have the proper features
set, leading to errors on writing.
-rwxr-xr-x | auto_update_tests.py | 4 | ||||
-rwxr-xr-x | check.py | 4 | ||||
-rw-r--r-- | src/tools/wasm-reduce.cpp | 8 | ||||
-rw-r--r-- | test/reduce/atomics-and-bulk-memory.wast | 27 | ||||
-rw-r--r-- | test/reduce/atomics-and-bulk-memory.wast.txt | 15 |
5 files changed, 52 insertions, 6 deletions
diff --git a/auto_update_tests.py b/auto_update_tests.py index 9f9a877b0..1135adeb2 100755 --- a/auto_update_tests.py +++ b/auto_update_tests.py @@ -114,8 +114,8 @@ def update_reduce_tests(): for t in shared.get_tests(shared.get_test_dir('reduce'), ['.wast']): print('..', os.path.basename(t)) # convert to wasm - support.run_command(shared.WASM_AS + [t, '-o', 'a.wasm']) - print(support.run_command(shared.WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec' % shared.WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm'])) + support.run_command(shared.WASM_AS + [t, '-o', 'a.wasm', '-all']) + print(support.run_command(shared.WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec -all' % shared.WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm'])) expected = t + '.txt' support.run_command(shared.WASM_DIS + ['c.wasm', '-o', expected]) @@ -159,8 +159,8 @@ def run_wasm_reduce_tests(): for t in shared.get_tests(shared.get_test_dir('reduce'), ['.wast']): print('..', os.path.basename(t)) # convert to wasm - support.run_command(shared.WASM_AS + [t, '-o', 'a.wasm']) - support.run_command(shared.WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec --detect-features ' % shared.WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm', '--timeout=4']) + support.run_command(shared.WASM_AS + [t, '-o', 'a.wasm', '-all']) + support.run_command(shared.WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec -all ' % shared.WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm', '--timeout=4']) expected = t + '.txt' support.run_command(shared.WASM_DIS + ['c.wasm', '-o', 'a.wat']) with open('a.wat') as seen: diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp index 0332b4712..1d5164397 100644 --- a/src/tools/wasm-reduce.cpp +++ b/src/tools/wasm-reduce.cpp @@ -346,10 +346,14 @@ struct Reducer void loadWorking() { module = make_unique<Module>(); - Module wasm; ModuleReader reader; reader.read(working, *module); - wasm.features = FeatureSet::All; + // If there is no features section, assume we may need them all (without + // this, a module with no features section but that uses e.g. atomics and + // bulk memory would not work). + if (!module->hasFeaturesSection) { + module->features = FeatureSet::All; + } builder = make_unique<Builder>(*module); setModule(module.get()); } diff --git a/test/reduce/atomics-and-bulk-memory.wast b/test/reduce/atomics-and-bulk-memory.wast new file mode 100644 index 000000000..a5b31d4be --- /dev/null +++ b/test/reduce/atomics-and-bulk-memory.wast @@ -0,0 +1,27 @@ +(module + (memory 1 1) + ;; this can be removed destructively + (data passive "some-data") + (func "foo" (result i32) + ;; this can be removed destructively + (memory.init 0 + (i32.const 3) + (i32.const 3) + (i32.const 3)) + (i32.atomic.store8 + (i32.const 0) + ;; an add that can be optimized + (i32.add + (i32.const 97) + (i32.const 2) + ) + ) + ;; add some nops and blocks for reduction to remove + (nop) + (block (result i32) + (i32.atomic.load8_u + (i32.const 0) + ) + ) + ) +) diff --git a/test/reduce/atomics-and-bulk-memory.wast.txt b/test/reduce/atomics-and-bulk-memory.wast.txt new file mode 100644 index 000000000..ace3f57d9 --- /dev/null +++ b/test/reduce/atomics-and-bulk-memory.wast.txt @@ -0,0 +1,15 @@ +(module + (type $none_=>_i32 (func (result i32))) + (memory $0 1 1) + (export "foo" (func $0)) + (func $0 (result i32) + (i32.atomic.store8 + (i32.const 0) + (i32.const 99) + ) + (i32.atomic.load8_u + (i32.const 0) + ) + ) +) + |