diff options
author | Alon Zakai <azakai@google.com> | 2024-02-21 15:33:13 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-21 15:33:13 -0800 |
commit | e4d2e7c08e758c513eb2a8b193a5bf4df589c947 (patch) | |
tree | 2c9cde5d01ff42324ba874543cdc9cf5602ebf29 | |
parent | 93b497068746283a786b045046afd1f4608ccfa3 (diff) | |
download | binaryen-e4d2e7c08e758c513eb2a8b193a5bf4df589c947.tar.gz binaryen-e4d2e7c08e758c513eb2a8b193a5bf4df589c947.tar.bz2 binaryen-e4d2e7c08e758c513eb2a8b193a5bf4df589c947.zip |
Validator: ArrayNew|InitData require Bulk Memory (#6331)
Those instructions refer to a data segment, which mean the DataCount section
must be emitted before them (so that, per the spec, they can be validated by
looking only at previous sections), which implies bulk-memory is needed.
-rw-r--r-- | src/wasm/wasm-validator.cpp | 8 | ||||
-rw-r--r-- | test/lit/validation/array-init-data.wast | 27 | ||||
-rw-r--r-- | test/lit/validation/array-new-data.wast | 25 |
3 files changed, 60 insertions, 0 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 3688587be..3fbcb0bfb 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -2909,6 +2909,10 @@ void FunctionValidator::visitArrayNew(ArrayNew* curr) { void FunctionValidator::visitArrayNewData(ArrayNewData* curr) { visitArrayNew(curr); + shouldBeTrue( + getModule()->features.hasBulkMemory(), + curr, + "Data segment operations require bulk memory [--enable-bulk-memory]"); if (!shouldBeTrue(getModule()->getDataSegment(curr->segment), curr, "array.new_data segment should exist")) { @@ -3175,6 +3179,10 @@ void FunctionValidator::visitArrayInit(ArrayInit* curr) { void FunctionValidator::visitArrayInitData(ArrayInitData* curr) { visitArrayInit(curr); + shouldBeTrue( + getModule()->features.hasBulkMemory(), + curr, + "Data segment operations require bulk memory [--enable-bulk-memory]"); shouldBeTrue(getModule()->getDataSegmentOrNull(curr->segment), curr, "array.init_data segment must exist"); diff --git a/test/lit/validation/array-init-data.wast b/test/lit/validation/array-init-data.wast new file mode 100644 index 000000000..088d0e9de --- /dev/null +++ b/test/lit/validation/array-init-data.wast @@ -0,0 +1,27 @@ +;; array.init_data refers to a data segment and therefore requires the datacount +;; section be emitted (so it can be validated, per the spec, using only previous +;; sections), which means bulk memory must be enabled. + +;; RUN: not wasm-opt --enable-reference-types --enable-gc %s 2>&1 | filecheck %s + +;; CHECK: Data segment operations require bulk memory + +(module + (type $0 (array i8)) + + (memory $0 16 17) + + (data $0 (i32.const 0) "") + + (func $0 + (array.init_data $0 $0 + (ref.null $0) + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) +) + +;; But it passes with the feature enabled. +;; RUN: wasm-opt --enable-reference-types --enable-gc --enable-bulk-memory %s diff --git a/test/lit/validation/array-new-data.wast b/test/lit/validation/array-new-data.wast new file mode 100644 index 000000000..e7d67ee34 --- /dev/null +++ b/test/lit/validation/array-new-data.wast @@ -0,0 +1,25 @@ +;; array.new_data refers to a data segment and therefore requires the datacount +;; section be emitted (so it can be validated, per the spec, using only previous +;; sections), which means bulk memory must be enabled. + +;; RUN: not wasm-opt --enable-reference-types --enable-gc %s 2>&1 | filecheck %s + +;; CHECK: Data segment operations require bulk memory + +(module + (type $0 (array i8)) + + (memory $0 16 17) + + (data $0 (i32.const 0) "") + + (func $0 (result (ref $0)) + (array.new_data $0 $0 + (i32.const 0) + (i32.const 0) + ) + ) +) + +;; But it passes with the feature enabled. +;; RUN: wasm-opt --enable-reference-types --enable-gc --enable-bulk-memory %s |