diff options
author | Daniel Wirtz <dcode@dcode.io> | 2020-09-29 21:24:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-29 21:24:02 +0200 |
commit | a629dc27bcb8022fad559ecdb2d3138e39183c6b (patch) | |
tree | 29cc4eba73071759fce48295db2c97df758c17ab /src/wasm | |
parent | fa4c884f4ebfde185c9d8a3ee4e54f96c57cebed (diff) | |
download | binaryen-a629dc27bcb8022fad559ecdb2d3138e39183c6b.tar.gz binaryen-a629dc27bcb8022fad559ecdb2d3138e39183c6b.tar.bz2 binaryen-a629dc27bcb8022fad559ecdb2d3138e39183c6b.zip |
GC: Fuzzing support for i31 (#3169)
Integrates `i31ref` types and instructions into the fuzzer, by assuming that `(i31.new (i32.const N))` is constant and hence suitable to be used in global initializers.
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/literal.cpp | 8 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 15 |
2 files changed, 12 insertions, 11 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index a7c14fdb6..d309be308 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -139,7 +139,11 @@ Literals Literal::makeZero(Type type) { Literal Literal::makeSingleZero(Type type) { assert(type.isSingle()); if (type.isRef()) { - return makeNull(type); + if (type == Type::i31ref) { + return makeI31(0); + } else { + return makeNull(type); + } } else { return makeFromInt32(0, type); } @@ -438,7 +442,7 @@ std::ostream& operator<<(std::ostream& o, Literal literal) { o << "eqref(null)"; break; case Type::i31ref: - o << "i31ref(" << literal.geti31(false) << ")"; + o << "i31ref(" << literal.geti31() << ")"; break; case Type::unreachable: WASM_UNREACHABLE("invalid type"); diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index c03a9b281..c857b202c 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -217,18 +217,15 @@ const char* getExpressionName(Expression* curr) { } Literal getSingleLiteralFromConstExpression(Expression* curr) { - if (auto* c = curr->dynCast<Const>()) { - return c->value; - } else if (auto* n = curr->dynCast<RefNull>()) { - return Literal::makeNull(n->type); - } else if (auto* r = curr->dynCast<RefFunc>()) { - return Literal::makeFunc(r->func); - } else { - WASM_UNREACHABLE("Not a constant expression"); - } + // TODO: Do we need this function given that Properties::getSingleLiteral + // (currently) does the same? + assert(Properties::isConstantExpression(curr)); + return Properties::getSingleLiteral(curr); } Literals getLiteralsFromConstExpression(Expression* curr) { + // TODO: Do we need this function given that Properties::getLiterals + // (currently) does the same? if (auto* t = curr->dynCast<TupleMake>()) { Literals values; for (auto* operand : t->operands) { |