summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-stack.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-03-09 12:30:36 -0800
committerGitHub <noreply@github.com>2021-03-09 12:30:36 -0800
commita1187630835e747ba7609296ab0ecb85df0b07b2 (patch)
treecb4a15e120785c8fc7f2172bbdd240e0ddc724ec /src/wasm/wasm-stack.cpp
parenta1d3e63f89e9d13daabf626033a66fe5b8a8bce1 (diff)
downloadbinaryen-a1187630835e747ba7609296ab0ecb85df0b07b2.tar.gz
binaryen-a1187630835e747ba7609296ab0ecb85df0b07b2.tar.bz2
binaryen-a1187630835e747ba7609296ab0ecb85df0b07b2.zip
[Wasm GC] Properly handle "typeindex" in the binary format (#3663)
We handled them as S63 instead of U32. That should be fine, as all U32 values fit in S63. But it is not strictly correct. The signed encoding may use an additional byte which is unnecessary, and there is an actual correctness issue where a U32 may be interpreted as a large negative S63 (because it sign extends a final bit that happens to be 1). May help #3656 but that testcase still does not pass even with this.
Diffstat (limited to 'src/wasm/wasm-stack.cpp')
-rw-r--r--src/wasm/wasm-stack.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index 0c7448c58..2c8bc051f 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -2030,12 +2030,12 @@ void BinaryInstWriter::visitBrOn(BrOn* curr) {
void BinaryInstWriter::visitRttCanon(RttCanon* curr) {
o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::RttCanon);
- parent.writeHeapType(curr->type.getRtt().heapType);
+ parent.writeIndexedHeapType(curr->type.getRtt().heapType);
}
void BinaryInstWriter::visitRttSub(RttSub* curr) {
o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::RttSub);
- parent.writeHeapType(curr->type.getRtt().heapType);
+ parent.writeIndexedHeapType(curr->type.getRtt().heapType);
}
void BinaryInstWriter::visitStructNew(StructNew* curr) {
@@ -2045,7 +2045,7 @@ void BinaryInstWriter::visitStructNew(StructNew* curr) {
} else {
o << U32LEB(BinaryConsts::StructNewWithRtt);
}
- parent.writeHeapType(curr->rtt->type.getHeapType());
+ parent.writeIndexedHeapType(curr->rtt->type.getHeapType());
}
void BinaryInstWriter::visitStructGet(StructGet* curr) {
@@ -2060,13 +2060,13 @@ void BinaryInstWriter::visitStructGet(StructGet* curr) {
op = BinaryConsts::StructGetU;
}
o << int8_t(BinaryConsts::GCPrefix) << U32LEB(op);
- parent.writeHeapType(heapType);
+ parent.writeIndexedHeapType(heapType);
o << U32LEB(curr->index);
}
void BinaryInstWriter::visitStructSet(StructSet* curr) {
o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::StructSet);
- parent.writeHeapType(curr->ref->type.getHeapType());
+ parent.writeIndexedHeapType(curr->ref->type.getHeapType());
o << U32LEB(curr->index);
}
@@ -2077,7 +2077,7 @@ void BinaryInstWriter::visitArrayNew(ArrayNew* curr) {
} else {
o << U32LEB(BinaryConsts::ArrayNewWithRtt);
}
- parent.writeHeapType(curr->rtt->type.getHeapType());
+ parent.writeIndexedHeapType(curr->rtt->type.getHeapType());
}
void BinaryInstWriter::visitArrayGet(ArrayGet* curr) {
@@ -2092,17 +2092,17 @@ void BinaryInstWriter::visitArrayGet(ArrayGet* curr) {
op = BinaryConsts::ArrayGetU;
}
o << int8_t(BinaryConsts::GCPrefix) << U32LEB(op);
- parent.writeHeapType(heapType);
+ parent.writeIndexedHeapType(heapType);
}
void BinaryInstWriter::visitArraySet(ArraySet* curr) {
o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::ArraySet);
- parent.writeHeapType(curr->ref->type.getHeapType());
+ parent.writeIndexedHeapType(curr->ref->type.getHeapType());
}
void BinaryInstWriter::visitArrayLen(ArrayLen* curr) {
o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::ArrayLen);
- parent.writeHeapType(curr->ref->type.getHeapType());
+ parent.writeIndexedHeapType(curr->ref->type.getHeapType());
}
void BinaryInstWriter::visitRefAs(RefAs* curr) {