From a1187630835e747ba7609296ab0ecb85df0b07b2 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 9 Mar 2021 12:30:36 -0800 Subject: [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. --- src/wasm/wasm-stack.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/wasm/wasm-stack.cpp') 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) { -- cgit v1.2.3