diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/properties.cpp | 8 | ||||
-rw-r--r-- | src/ir/properties.h | 15 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/ir/properties.cpp b/src/ir/properties.cpp index 4ade8aa10..b564b3bf1 100644 --- a/src/ir/properties.cpp +++ b/src/ir/properties.cpp @@ -36,6 +36,8 @@ bool isGenerative(Expression* curr, FeatureSet features) { return scanner.generative; } +// Checks an expression in a shallow manner (i.e., does not check children) as +// to whether it is valid in a wasm constant expression. static bool isValidInConstantExpression(Module& wasm, Expression* expr) { if (isSingleConstantExpression(expr) || expr->is<StructNew>() || expr->is<ArrayNew>() || expr->is<ArrayNewFixed>() || expr->is<I31New>() || @@ -43,6 +45,12 @@ static bool isValidInConstantExpression(Module& wasm, Expression* expr) { return true; } + if (auto* refAs = expr->dynCast<RefAs>()) { + if (refAs->op == ExternExternalize || refAs->op == ExternInternalize) { + return true; + } + } + if (auto* get = expr->dynCast<GlobalGet>()) { auto* g = wasm.getGlobalOrNull(get->name); // This is called from the validator, so we have to handle non-existent diff --git a/src/ir/properties.h b/src/ir/properties.h index 13eea6ba2..d47cf774b 100644 --- a/src/ir/properties.h +++ b/src/ir/properties.h @@ -82,10 +82,13 @@ inline bool isNamedControlFlow(Expression* curr) { // runtime will be equal as well. TODO: combine this with // isValidInConstantExpression or find better names(#4845) inline bool isSingleConstantExpression(const Expression* curr) { + if (auto* refAs = curr->dynCast<RefAs>()) { + if (refAs->op == ExternExternalize || refAs->op == ExternInternalize) { + return isSingleConstantExpression(refAs->value); + } + } return curr->is<Const>() || curr->is<RefNull>() || curr->is<RefFunc>() || - curr->is<StringConst>() || - (curr->is<RefAs>() && (curr->cast<RefAs>()->op == ExternExternalize || - curr->cast<RefAs>()->op == ExternInternalize)); + curr->is<StringConst>(); } inline bool isConstantExpression(const Expression* curr) { @@ -120,6 +123,12 @@ inline Literal getLiteral(const Expression* curr) { } } else if (auto* s = curr->dynCast<StringConst>()) { return Literal(s->string.toString()); + } else if (auto* r = curr->dynCast<RefAs>()) { + if (r->op == ExternExternalize) { + return getLiteral(r->value).externalize(); + } else if (r->op == ExternInternalize) { + return getLiteral(r->value).internalize(); + } } WASM_UNREACHABLE("non-constant expression"); } |