summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp9
-rw-r--r--src/wasm/wasm-s-parser.cpp12
-rw-r--r--src/wasm/wasm-stack.cpp8
-rw-r--r--src/wasm/wasm-validator.cpp2
4 files changed, 22 insertions, 9 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 0160ffaf6..386f89060 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -6893,11 +6893,14 @@ bool WasmBinaryBuilder::maybeVisitI31Get(Expression*& out, uint32_t code) {
}
bool WasmBinaryBuilder::maybeVisitRefTest(Expression*& out, uint32_t code) {
- if (code == BinaryConsts::RefTestStatic || code == BinaryConsts::RefTest) {
+ if (code == BinaryConsts::RefTestStatic || code == BinaryConsts::RefTest ||
+ code == BinaryConsts::RefTestNull) {
bool legacy = code == BinaryConsts::RefTestStatic;
- auto intendedType = legacy ? getIndexedHeapType() : getHeapType();
+ auto castType = legacy ? getIndexedHeapType() : getHeapType();
+ auto nullability =
+ (code == BinaryConsts::RefTestNull) ? Nullable : NonNullable;
auto* ref = popNonVoidExpression();
- out = Builder(wasm).makeRefTest(ref, intendedType);
+ out = Builder(wasm).makeRefTest(ref, Type(castType, nullability));
return true;
}
return false;
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index cf287d8a1..4fdc29a66 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -2776,9 +2776,15 @@ Expression* SExpressionWasmBuilder::makeI31Get(Element& s, bool signed_) {
}
Expression* SExpressionWasmBuilder::makeRefTest(Element& s) {
- auto heapType = parseHeapType(*s[1]);
- auto* ref = parseExpression(*s[2]);
- return Builder(wasm).makeRefTest(ref, heapType);
+ int i = 1;
+ auto nullability = NonNullable;
+ if (s[0]->str().str != "ref.test_static" && s[1]->str().str == "null") {
+ nullability = Nullable;
+ ++i;
+ }
+ auto heapType = parseHeapType(*s[i++]);
+ auto* ref = parseExpression(*s[i++]);
+ return Builder(wasm).makeRefTest(ref, Type(heapType, nullability));
}
Expression* SExpressionWasmBuilder::makeRefCast(Element& s) {
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index 911447b48..e24060f2a 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -2025,8 +2025,12 @@ void BinaryInstWriter::visitCallRef(CallRef* curr) {
void BinaryInstWriter::visitRefTest(RefTest* curr) {
o << int8_t(BinaryConsts::GCPrefix);
- o << U32LEB(BinaryConsts::RefTest);
- parent.writeHeapType(curr->intendedType);
+ if (curr->castType.isNullable()) {
+ o << U32LEB(BinaryConsts::RefTestNull);
+ } else {
+ o << U32LEB(BinaryConsts::RefTest);
+ }
+ parent.writeHeapType(curr->castType.getHeapType());
}
void BinaryInstWriter::visitRefCast(RefCast* curr) {
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index b102ecb1c..68fb58ec4 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -2513,7 +2513,7 @@ void FunctionValidator::visitRefTest(RefTest* curr) {
return;
}
shouldBeEqual(
- curr->intendedType.getBottom(),
+ curr->castType.getHeapType().getBottom(),
curr->ref->type.getHeapType().getBottom(),
curr,
"ref.test target type and ref type must have a common supertype");