Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/wasm/literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,14 @@ void Literal::getBits(uint8_t (&buf)[16]) const {
}

bool Literal::operator==(const Literal& other) const {
// As a special case, shared and unshared i31 can compare equal even if their
// types are different (because one is shared and the other is not).
if (type.isRef() && other.type.isRef() && type.getHeapType().isBasic() &&
other.type.getHeapType().isBasic() &&
type.getHeapType().getBasic(Unshared) == HeapType::i31 &&
other.type.getHeapType().getBasic(Unshared) == HeapType::i31) {
return i32 == other.i32;
}
if (type != other.type) {
return false;
}
Expand Down Expand Up @@ -445,9 +453,7 @@ bool Literal::operator==(const Literal& other) const {
if (type.isData()) {
return gcData == other.gcData;
}
if (type.getHeapType() == HeapType::i31) {
return i32 == other.i32;
}
// i31 already handled.
WASM_UNREACHABLE("unexpected type");
}
WASM_UNREACHABLE("unexpected type");
Expand Down
11 changes: 11 additions & 0 deletions test/spec/shared-polymorphism.wast
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@
(extern.convert_any (local.get 0))
)
)

(module
(func (export "eq") (param i32 i32) (result i32)
(ref.eq (ref.i31 (local.get 0)) (ref.i31_shared (local.get 1)))
)
)

(assert_return (invoke "eq" (i32.const 0) (i32.const 0)) (i32.const 1))
(assert_return (invoke "eq" (i32.const 0) (i32.const 1)) (i32.const 0))
(assert_return (invoke "eq" (i32.const 1) (i32.const 0)) (i32.const 0))
(assert_return (invoke "eq" (i32.const 1) (i32.const 1)) (i32.const 1))