diff options
author | Alon Zakai <azakai@google.com> | 2024-03-21 10:14:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-21 10:14:37 -0700 |
commit | afcb387d84678058073d81a1fd760e0b35d6347d (patch) | |
tree | f50ea3c7195edbe7ee32913f3675f3ffa5a04530 /src/wasm/wasm-stack.cpp | |
parent | b1535dac8f544c5000c136d696738a27fc931660 (diff) | |
download | binaryen-afcb387d84678058073d81a1fd760e0b35d6347d.tar.gz binaryen-afcb387d84678058073d81a1fd760e0b35d6347d.tar.bz2 binaryen-afcb387d84678058073d81a1fd760e0b35d6347d.zip |
[Strings] Emit unreachable when a string instruction cannot be emitted properly (#6415)
See WebAssembly/stringref#66
Diffstat (limited to 'src/wasm/wasm-stack.cpp')
-rw-r--r-- | src/wasm/wasm-stack.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index 31742681d..4e3194e84 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -2293,6 +2293,14 @@ void BinaryInstWriter::visitRefAs(RefAs* curr) { } void BinaryInstWriter::visitStringNew(StringNew* curr) { + if (curr->ptr->type.isNull()) { + // This is a bottom type, so this is an array-receiving operation that does + // not receive an array. The spec allows this, but V8 does not, see + // https://github.com/WebAssembly/stringref/issues/66 + // For now, just emit an unreachable here as this will definitely trap. + emitUnreachable(); + return; + } o << int8_t(BinaryConsts::GCPrefix); switch (curr->op) { case StringNewUTF8: @@ -2371,6 +2379,11 @@ void BinaryInstWriter::visitStringMeasure(StringMeasure* curr) { } void BinaryInstWriter::visitStringEncode(StringEncode* curr) { + if (curr->ptr->type.isNull()) { + // See visitStringNew. + emitUnreachable(); + return; + } o << int8_t(BinaryConsts::GCPrefix); switch (curr->op) { case StringEncodeUTF8: |