diff options
author | Thomas Lively <tlively@google.com> | 2024-01-03 14:04:26 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-03 14:04:26 -0800 |
commit | 328bd7a7d6cce32e893c5839b95574f8a3d8bd9a (patch) | |
tree | bbf0cd57bb1940d7102dedc371b21df88d62ebc4 /src/wasm/wasm-ir-builder.cpp | |
parent | c923521a61205dd2358201e311b009886e095381 (diff) | |
download | binaryen-328bd7a7d6cce32e893c5839b95574f8a3d8bd9a.tar.gz binaryen-328bd7a7d6cce32e893c5839b95574f8a3d8bd9a.tar.bz2 binaryen-328bd7a7d6cce32e893c5839b95574f8a3d8bd9a.zip |
[Parser] Parse br_on_cast{_fail} input annotations (#6198)
And validate in IRBuilder both that the input annotation is valid and that the
input matches it.
Diffstat (limited to 'src/wasm/wasm-ir-builder.cpp')
-rw-r--r-- | src/wasm/wasm-ir-builder.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index 3cfe0ea30..43a989c6e 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -1420,12 +1420,20 @@ Result<> IRBuilder::makeRefCast(Type type) { return Ok{}; } -Result<> IRBuilder::makeBrOn(Index label, BrOnOp op, Type castType) { +Result<> IRBuilder::makeBrOn(Index label, BrOnOp op, Type in, Type out) { BrOn curr; CHECK_ERR(visitBrOn(&curr)); + if (out != Type::none) { + if (!Type::isSubType(out, in)) { + return Err{"output type is not a subtype of the input type"}; + } + if (!Type::isSubType(curr.ref->type, in)) { + return Err{"expected input to match input type annotation"}; + } + } auto name = getLabelName(label); CHECK_ERR(name); - push(builder.makeBrOn(op, *name, curr.ref, castType)); + push(builder.makeBrOn(op, *name, curr.ref, out)); return Ok{}; } |