From ef674ecb40d1dcdcb39a33a7d28772edaeff63b8 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 20 Mar 2023 15:14:52 -0700 Subject: [Wasm GC] Fix detection of externalize/internalize as constant (#5592) Both isValidInConstantExpression and isSingleConstantExpression must look recursively at the internals of a RefAs that externalizes and internalizes, or else we might do something like externalize a local.get, which is not constant. getLiteral must handle externalize/internalize as well, and return a properly- modified literal. Without these fixes the testcase hits different internal assertions, and we either fail to recognize something is constant or not, or think that it is but fail to produce a literal for it. --- src/ir/properties.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/ir/properties.cpp') 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() || expr->is() || expr->is() || expr->is() || @@ -43,6 +45,12 @@ static bool isValidInConstantExpression(Module& wasm, Expression* expr) { return true; } + if (auto* refAs = expr->dynCast()) { + if (refAs->op == ExternExternalize || refAs->op == ExternInternalize) { + return true; + } + } + if (auto* get = expr->dynCast()) { auto* g = wasm.getGlobalOrNull(get->name); // This is called from the validator, so we have to handle non-existent -- cgit v1.2.3