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
27 changes: 18 additions & 9 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,12 @@
}

void FunctionValidator::visitConst(Const* curr) {
shouldBeTrue(curr->type.getFeatures().isSubsetOf(getModule()->features),
curr,
"all used features should be allowed");
auto required = curr->type.getFeatures();
if (!shouldBeTrue(required.isSubsetOf(getModule()->features),
curr,
"Const type requires additional features")) {

Check warning on line 1048 in src/wasm/wasm-validator.cpp

View workflow job for this annotation

GitHub Actions / coverage

One-sided branch in diff

Branch `!shouldBeTrue(required.isSubsetOf(getModule()->features), ...` -> missing TRUE branch (True: 0x, False: 48917x)
getStream() << getMissingFeaturesList(*getModule(), required) << '\n';
}

Check warning on line 1050 in src/wasm/wasm-validator.cpp

View workflow job for this annotation

GitHub Actions / coverage

Uncovered diff lines

Lines 1049-1050 not executed by tests (0x)
}

void FunctionValidator::visitLocalGet(LocalGet* curr) {
Expand Down Expand Up @@ -2063,9 +2066,12 @@
case InvalidBinary:
WASM_UNREACHABLE("invliad binary op");
}
shouldBeTrue(Features::get(curr->op).isSubsetOf(getModule()->features),
curr,
"all used features should be allowed");
auto required = Features::get(curr->op);
if (!shouldBeTrue(required.isSubsetOf(getModule()->features),
curr,
"Binary operation requires additional features")) {

Check warning on line 2072 in src/wasm/wasm-validator.cpp

View workflow job for this annotation

GitHub Actions / coverage

One-sided branch in diff

Branch `!shouldBeTrue(required.isSubsetOf(getModule()->features), ...` -> missing TRUE branch (True: 0x, False: 27113x)
getStream() << getMissingFeaturesList(*getModule(), required) << '\n';
}

Check warning on line 2074 in src/wasm/wasm-validator.cpp

View workflow job for this annotation

GitHub Actions / coverage

Uncovered diff lines

Lines 2073-2074 not executed by tests (0x)
}

void FunctionValidator::visitUnary(Unary* curr) {
Expand Down Expand Up @@ -2373,9 +2379,12 @@
case InvalidUnary:
WASM_UNREACHABLE("invalid unary op");
}
shouldBeTrue(Features::get(curr->op).isSubsetOf(getModule()->features),
curr,
"all used features should be allowed");
auto required = Features::get(curr->op);
if (!shouldBeTrue(required.isSubsetOf(getModule()->features),
curr,
"Unary operation requires additional features")) {

Check warning on line 2385 in src/wasm/wasm-validator.cpp

View workflow job for this annotation

GitHub Actions / coverage

One-sided branch in diff

Branch `!shouldBeTrue(required.isSubsetOf(getModule()->features), ...` -> missing TRUE branch (True: 0x, False: 3663x)
getStream() << getMissingFeaturesList(*getModule(), required) << '\n';
}

Check warning on line 2387 in src/wasm/wasm-validator.cpp

View workflow job for this annotation

GitHub Actions / coverage

Uncovered diff lines

Lines 2386-2387 not executed by tests (0x)
}

void FunctionValidator::visitSelect(Select* curr) {
Expand Down
48 changes: 48 additions & 0 deletions test/lit/validation/binary-features.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
;; Test that validator errors when binary operations use features that are not
;; enabled.

;; RUN: not wasm-opt %s 2>&1 | filecheck %s --check-prefix NONE
;; RUN: not wasm-opt %s --enable-simd 2>&1 | filecheck %s --check-prefix SIMD
;; RUN: wasm-opt %s --enable-simd --enable-relaxed-simd -o - -S | filecheck %s --check-prefix ALL

;; NONE: Binary operation requires additional features, on
;; NONE-NEXT: (i8x16.add
;; NONE-NEXT: (unreachable)
;; NONE-NEXT: (unreachable)
;; NONE-NEXT: )
;; NONE-NEXT: [--enable-simd]
;; NONE-NEXT: [wasm-validator error in function relaxed] unexpected false: Binary operation requires additional features, on
;; NONE-NEXT: (f32x4.relaxed_min
;; NONE-NEXT: (unreachable)
;; NONE-NEXT: (unreachable)
;; NONE-NEXT: )
;; NONE-NEXT: [--enable-simd --enable-relaxed-simd]
;; NONE-NEXT: Fatal: error validating input

;; SIMD: [wasm-validator error in function relaxed] unexpected false: Binary operation requires additional features, on
;; SIMD-NEXT: (f32x4.relaxed_min
;; SIMD-NEXT: (unreachable)
;; SIMD-NEXT: (unreachable)
;; SIMD-NEXT: )
;; SIMD-NEXT: [--enable-relaxed-simd]
;; SIMD-NEXT: Fatal: error validating input

;; ALL: (i8x16.add
;; ALL: (f32x4.relaxed_min
;; ALL: (i32.add

(module
(func $simd
(drop
(i8x16.add (unreachable) (unreachable))
)
)
(func $relaxed
(drop
(f32x4.relaxed_min (unreachable) (unreachable))
)
)
(func $mvp (result i32)
(i32.add (i32.const 1) (i32.const 2))
)
)
26 changes: 26 additions & 0 deletions test/lit/validation/const-features.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
;; Test that validator errors when constants require features that are not
;; enabled.

;; RUN: not wasm-opt %s 2>&1 | filecheck %s --check-prefix NO-SIMD
;; RUN: wasm-opt %s --enable-simd -o - -S | filecheck %s --check-prefix SIMD

;; NO-SIMD: Const type requires additional features, on
;; NO-SIMD-NEXT: (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000)
;; NO-SIMD-NEXT: [--enable-simd]
;; NO-SIMD-NEXT: Fatal: error validating input

;; SIMD: (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000)
;; SIMD: (i32.const 0)

(module
(func $v128
(drop
(v128.const i32x4 0 0 0 0)
)
)
(func $i32
(drop
(i32.const 0)
)
)
)
Loading
Loading