Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -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");
Expand Down
27 changes: 27 additions & 0 deletions test/lit/validation/array-init-data.wast
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions test/lit/validation/array-new-data.wast
Original file line number Diff line number Diff line change
@@ -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