diff options
author | Thomas Lively <tlively@google.com> | 2022-10-13 16:46:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-13 16:46:21 -0500 |
commit | b11a8e06f9d098160a6d0c333b485249cd544d99 (patch) | |
tree | aa22d42af8b454b69fedc1720f9543cc09044769 /src/wasm/wat-parser.cpp | |
parent | bc23c8f45bd1c2808d0871e7f1c9dbbdb3bc4ae8 (diff) | |
download | binaryen-b11a8e06f9d098160a6d0c333b485249cd544d99.tar.gz binaryen-b11a8e06f9d098160a6d0c333b485249cd544d99.tar.bz2 binaryen-b11a8e06f9d098160a6d0c333b485249cd544d99.zip |
[Parser] Validate type annotations on `select` (#5139)
Since the type annotations are not stored explicitly in Binaryen IR, we have to
validate them in the parser. Implement this and fix a newly-caught incorrect
annotation in the tests.
Diffstat (limited to 'src/wasm/wat-parser.cpp')
-rw-r--r-- | src/wasm/wat-parser.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/wasm/wat-parser.cpp b/src/wasm/wat-parser.cpp index 1ee2bd2c8..e17701094 100644 --- a/src/wasm/wat-parser.cpp +++ b/src/wasm/wat-parser.cpp @@ -739,7 +739,7 @@ template<typename Ctx> struct InstrParserCtx : TypeParserCtx<Ctx> { CHECK_ERR(val); return push(pos, builder.makeUnary(op, *val)); } - Result<> makeSelect(Index pos, typename TypeParserCtx<Ctx>::ResultsT* res) { + Result<> makeSelect(Index pos, std::vector<Type>* res) { if (res && res->size() > 1) { return self().in.err(pos, "select may not have more than one result type"); @@ -750,6 +750,10 @@ template<typename Ctx> struct InstrParserCtx : TypeParserCtx<Ctx> { CHECK_ERR(ifFalse); auto ifTrue = pop(pos); CHECK_ERR(ifTrue); + auto select = builder.makeSelect(*cond, *ifTrue, *ifFalse); + if (res && !res->empty() && !Type::isSubType(select->type, res->front())) { + return self().in.err(pos, "select type annotation is incorrect"); + } return push(pos, builder.makeSelect(*cond, *ifTrue, *ifFalse)); } Result<> makeDrop(Index pos) { |