Skip to content

Commit 85ae738

Browse files
kripkenradekdoulik
authored andcommitted
Error on multivalue inputs that we do not handle (WebAssembly#5962)
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
1 parent d2c54c5 commit 85ae738

5 files changed

+44
-2
lines changed

src/wasm/wasm-binary.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,11 @@ Type WasmBinaryReader::getType(int initial) {
20372037
// Single value types are negative; signature indices are non-negative
20382038
if (initial >= 0) {
20392039
// TODO: Handle block input types properly.
2040-
return getSignatureByTypeIndex(initial).results;
2040+
auto sig = getSignatureByTypeIndex(initial);
2041+
if (sig.params != Type::none) {
2042+
throwError("control flow inputs are not supported yet");
2043+
}
2044+
return sig.results;
20412045
}
20422046
Type type;
20432047
if (getBasicType(initial, type)) {
@@ -2088,7 +2092,7 @@ HeapType WasmBinaryReader::getIndexedHeapType() {
20882092
Type WasmBinaryReader::getConcreteType() {
20892093
auto type = getType();
20902094
if (!type.isConcrete()) {
2091-
throw ParseException("non-concrete type when one expected");
2095+
throwError("non-concrete type when one expected");
20922096
}
20932097
return type;
20942098
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
;; Test that we error properly on a block with a bad multivalue (inputs).
2+
3+
;; File contents:
4+
;;
5+
;; (module
6+
;; (func $test
7+
;; i32.const 0
8+
;; (block (param i32)
9+
;; drop
10+
;; )
11+
;; )
12+
;; )
13+
14+
;; RUN: not wasm-opt -all %s.wasm 2>&1 | filecheck %s
15+
16+
;; CHECK: control flow inputs are not supported yet
34 Bytes
Binary file not shown.
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
;; Test that we error properly on an if with a bad multivalue (inputs).
2+
3+
;; File contents:
4+
;;
5+
;; (module
6+
;; (func $test
7+
;; i32.const 0
8+
;; i32.const 1
9+
;; (if (param i32)
10+
;; (then
11+
;; drop
12+
;; )
13+
;; (else
14+
;; drop
15+
;; )
16+
;; )
17+
;; )
18+
;; )
19+
20+
;; RUN: not wasm-opt -all %s.wasm 2>&1 | filecheck %s
21+
22+
;; CHECK: control flow inputs are not supported yet
38 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)