summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-02-13 15:32:02 -0800
committerGitHub <noreply@github.com>2024-02-13 15:32:02 -0800
commit32a27828b5b8312e3a289f3310585720b14ebbd8 (patch)
tree4eb0e568b7d38ea00477cba7ddd117fab9cbfe68 /src
parentcdc9ad97c6b8764294b4a017f73fa2c82cce5082 (diff)
downloadbinaryen-32a27828b5b8312e3a289f3310585720b14ebbd8.tar.gz
binaryen-32a27828b5b8312e3a289f3310585720b14ebbd8.tar.bz2
binaryen-32a27828b5b8312e3a289f3310585720b14ebbd8.zip
StringLowering: Hack around if issue with bottom types (#6303)
Replacing the string heap type with extern is dangerous as they do not share top/bottom types. In practice this works out almost everywhere except for a few ifs, which we can fix up as a hack for now.
Diffstat (limited to 'src')
-rw-r--r--src/passes/StringLowering.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/passes/StringLowering.cpp b/src/passes/StringLowering.cpp
index f9930d946..1a5610608 100644
--- a/src/passes/StringLowering.cpp
+++ b/src/passes/StringLowering.cpp
@@ -406,6 +406,27 @@ struct StringLowering : public StringGathering {
WASM_UNREACHABLE("TODO: all string.slice*");
}
}
+
+ // Additional hacks.
+
+ void visitIf(If* curr) {
+ // Before the lowering we could have one arm be a ref.null none and the
+ // other a stringref; after the lowering that is invalid, because the
+ // string is now extern, which has no shared ancestor with none. Fix
+ // that up manually in the simple case of an if arm with a null by
+ // correcting the null's type. This is of course wildly insufficient (we
+ // need selects and blocks and all other joins) but in practice this is
+ // enough for now. TODO extend as needed
+ if (curr->type.isRef() && curr->type.getHeapType() == HeapType::ext) {
+ auto fixArm = [](Expression* arm) {
+ if (auto* null = arm->dynCast<RefNull>()) {
+ null->finalize(HeapType::noext);
+ }
+ };
+ fixArm(curr->ifTrue);
+ fixArm(curr->ifFalse);
+ }
+ }
};
Replacer replacer(*this);