diff options
author | Alon Zakai <azakai@google.com> | 2022-07-25 12:47:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-25 19:47:44 +0000 |
commit | 68e2ed11e86e72cc4e12a1b4026ef19d5149fda9 (patch) | |
tree | ad4ee672468c5fdf41be4bb612e070de66c27a5b /src/wasm | |
parent | 2db1e13f731e22fe53fbfebef6e4a15c043a587e (diff) | |
download | binaryen-68e2ed11e86e72cc4e12a1b4026ef19d5149fda9.tar.gz binaryen-68e2ed11e86e72cc4e12a1b4026ef19d5149fda9.tar.bz2 binaryen-68e2ed11e86e72cc4e12a1b4026ef19d5149fda9.zip |
[Wasm GC] Properly represent nulls in i31 (#4819)
The encoding here is simple: we store i31 values in the literal.i32
field. The top bit says if a value exists, which means literal.i32 == 0 is the
same as null.
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/literal.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 85e93f912..608018d8b 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -229,11 +229,7 @@ Literals Literal::makeNegOnes(Type type) { Literal Literal::makeZero(Type type) { assert(type.isSingle()); if (type.isRef()) { - if (type.getHeapType() == HeapType::i31) { - return makeI31(0); - } else { - return makeNull(type.getHeapType()); - } + return makeNull(type.getHeapType()); } else if (type.isRtt()) { return Literal(type); } else { @@ -515,7 +511,11 @@ std::ostream& operator<<(std::ostream& o, Literal literal) { o << "eqref(null)"; break; case HeapType::i31: - o << "i31ref(" << literal.geti31() << ")"; + if (literal.isNull()) { + o << "i31ref(null)"; + } else { + o << "i31ref(" << literal.geti31() << ")"; + } break; case HeapType::func: case HeapType::data: |