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/ir | |
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/ir')
-rw-r--r-- | src/ir/global-utils.h | 6 | ||||
-rw-r--r-- | src/ir/properties.h | 18 |
2 files changed, 15 insertions, 9 deletions
diff --git a/src/ir/global-utils.h b/src/ir/global-utils.h index b575d6952..7dc4c6af3 100644 --- a/src/ir/global-utils.h +++ b/src/ir/global-utils.h @@ -56,15 +56,13 @@ getGlobalInitializedToImport(Module& wasm, Name module, Name base) { inline bool canInitializeGlobal(const Expression* curr) { if (auto* tuple = curr->dynCast<TupleMake>()) { for (auto* op : tuple->operands) { - if (!op->is<Const>() && !op->is<RefNull>() && - !op->is<RefFunc>() & !op->is<GlobalGet>()) { + if (!Properties::isSingleConstantExpression(op) && !op->is<GlobalGet>()) { return false; } } return true; } - return curr->is<Const>() || curr->is<RefNull>() || curr->is<RefFunc>() || - curr->is<GlobalGet>(); + return Properties::isSingleConstantExpression(curr) || curr->is<GlobalGet>(); } } // namespace GlobalUtils diff --git a/src/ir/properties.h b/src/ir/properties.h index 56723631a..d0495f4a9 100644 --- a/src/ir/properties.h +++ b/src/ir/properties.h @@ -79,13 +79,18 @@ inline bool isNamedControlFlow(Expression* curr) { return false; } +inline bool isSingleConstantExpression(const Expression* curr) { + return curr->is<Const>() || curr->is<RefNull>() || curr->is<RefFunc>() || + (curr->is<I31New>() && curr->cast<I31New>()->value->is<Const>()); +} + inline bool isConstantExpression(const Expression* curr) { - if (curr->is<Const>() || curr->is<RefNull>() || curr->is<RefFunc>()) { + if (isSingleConstantExpression(curr)) { return true; } if (auto* tuple = curr->dynCast<TupleMake>()) { for (auto* op : tuple->operands) { - if (!op->is<Const>() && !op->is<RefNull>() && !op->is<RefFunc>()) { + if (!isSingleConstantExpression(op)) { return false; } } @@ -101,13 +106,16 @@ inline Literal getSingleLiteral(const Expression* curr) { return Literal(n->type); } else if (auto* r = curr->dynCast<RefFunc>()) { return Literal(r->func); - } else { - WASM_UNREACHABLE("non-constant expression"); + } else if (auto* i = curr->dynCast<I31New>()) { + if (auto* c = i->value->dynCast<Const>()) { + return Literal::makeI31(c->value.geti32()); + } } + WASM_UNREACHABLE("non-constant expression"); } inline Literals getLiterals(const Expression* curr) { - if (curr->is<Const>() || curr->is<RefNull>() || curr->is<RefFunc>()) { + if (isSingleConstantExpression(curr)) { return {getSingleLiteral(curr)}; } else if (auto* tuple = curr->dynCast<TupleMake>()) { Literals literals; |