Skip to content

Commit

Permalink
Error on multivalue inputs that we do not handle (WebAssembly#5962)
Browse files Browse the repository at this point in the history
Before in getType() we silently dropped the params of a signature type. Now we verify that
it is none, or we error.

Helps WebAssembly#5950
  • Loading branch information
kripken authored and radekdoulik committed Jul 12, 2024
1 parent d2c54c5 commit 85ae738
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,11 @@ Type WasmBinaryReader::getType(int initial) {
// Single value types are negative; signature indices are non-negative
if (initial >= 0) {
// TODO: Handle block input types properly.
return getSignatureByTypeIndex(initial).results;
auto sig = getSignatureByTypeIndex(initial);
if (sig.params != Type::none) {
throwError("control flow inputs are not supported yet");
}
return sig.results;
}
Type type;
if (getBasicType(initial, type)) {
Expand Down Expand Up @@ -2088,7 +2092,7 @@ HeapType WasmBinaryReader::getIndexedHeapType() {
Type WasmBinaryReader::getConcreteType() {
auto type = getType();
if (!type.isConcrete()) {
throw ParseException("non-concrete type when one expected");
throwError("non-concrete type when one expected");
}
return type;
}
Expand Down
16 changes: 16 additions & 0 deletions test/lit/binary/bad-multivalue-block.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
;; Test that we error properly on a block with a bad multivalue (inputs).

;; File contents:
;;
;; (module
;; (func $test
;; i32.const 0
;; (block (param i32)
;; drop
;; )
;; )
;; )

;; RUN: not wasm-opt -all %s.wasm 2>&1 | filecheck %s

;; CHECK: control flow inputs are not supported yet
Binary file added test/lit/binary/bad-multivalue-block.test.wasm
Binary file not shown.
22 changes: 22 additions & 0 deletions test/lit/binary/bad-multivalue-if.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
;; Test that we error properly on an if with a bad multivalue (inputs).

;; File contents:
;;
;; (module
;; (func $test
;; i32.const 0
;; i32.const 1
;; (if (param i32)
;; (then
;; drop
;; )
;; (else
;; drop
;; )
;; )
;; )
;; )

;; RUN: not wasm-opt -all %s.wasm 2>&1 | filecheck %s

;; CHECK: control flow inputs are not supported yet
Binary file added test/lit/binary/bad-multivalue-if.test.wasm
Binary file not shown.

0 comments on commit 85ae738

Please sign in to comment.