summaryrefslogtreecommitdiff
path: root/src/passes
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-04-23 08:33:43 -0700
committerGitHub <noreply@github.com>2024-04-23 08:33:43 -0700
commit4bbae113dc144f80ff4880c74c7068a9f7b14295 (patch)
tree568b756da8f53a148b1691a063f5a7f9a8c56466 /src/passes
parentbceb02d545aeabb21797ef4148e0f713c57e0e0d (diff)
downloadbinaryen-4bbae113dc144f80ff4880c74c7068a9f7b14295.tar.gz
binaryen-4bbae113dc144f80ff4880c74c7068a9f7b14295.tar.bz2
binaryen-4bbae113dc144f80ff4880c74c7068a9f7b14295.zip
Precompute: Ignore mutable arrays in StringNew (#6522)
All Struct/Array operations must ignore mutable fields in Precompute atm, which we did, but StringNew has an array variant that does an effective ArrayGet operation, which we didn't handle.
Diffstat (limited to 'src/passes')
-rw-r--r--src/passes/Precompute.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/passes/Precompute.cpp b/src/passes/Precompute.cpp
index 822b8ab16..4f9ad046d 100644
--- a/src/passes/Precompute.cpp
+++ b/src/passes/Precompute.cpp
@@ -195,6 +195,28 @@ public:
return Literal(canonical, curr->type.getHeapType());
}
+ Flow visitStringNew(StringNew* curr) {
+ if (curr->op != StringNewWTF16Array) {
+ // TODO: handle other string ops. For now we focus on JS-like strings.
+ return Flow(NONCONSTANT_FLOW);
+ }
+
+ // string.encode_wtf16_array is effectively an Array read operation, so
+ // just like ArrayGet above we must check for immutability.
+ auto ptrType = curr->ptr->type;
+ if (ptrType.isRef()) {
+ auto heapType = ptrType.getHeapType();
+ if (heapType.isArray()) {
+ if (heapType.getArray().element.mutable_ == Immutable) {
+ return Super::visitStringNew(curr);
+ }
+ }
+ }
+
+ // Otherwise, this is mutable or unreachable or otherwise uninteresting.
+ return Flow(NONCONSTANT_FLOW);
+ }
+
Flow visitStringEncode(StringEncode* curr) {
// string.encode_wtf16_array is effectively an Array write operation, so
// just like ArraySet and ArrayCopy above we must mark it as disallowed