Skip to content

Commit

Permalink
[Strings] Emit unreachable when a string instruction cannot be emitte…
Browse files Browse the repository at this point in the history
…d properly (#6415)

See WebAssembly/stringref#66
  • Loading branch information
kripken authored Mar 21, 2024
1 parent b1535da commit afcb387
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/wasm/wasm-stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit afcb387

Please sign in to comment.