summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-01-25 13:26:04 -0800
committerGitHub <noreply@github.com>2024-01-25 13:26:04 -0800
commit5fb2137d7f1272b7b107f0413190ad94bb69a73b (patch)
treec455db5364de1616804a05f5edee0c54219119e9
parent662835a88f6f47d5b1451b453046ae80b4b0fc62 (diff)
downloadbinaryen-5fb2137d7f1272b7b107f0413190ad94bb69a73b.tar.gz
binaryen-5fb2137d7f1272b7b107f0413190ad94bb69a73b.tar.bz2
binaryen-5fb2137d7f1272b7b107f0413190ad94bb69a73b.zip
MemoryPacking: Ignore empty segments (#6243)
They might trap. Leave that for RemoveUnusedModuleElements. Fixes #6230
-rw-r--r--src/passes/MemoryPacking.cpp7
-rw-r--r--test/lit/passes/memory-packing_all-features.wast7
2 files changed, 13 insertions, 1 deletions
diff --git a/src/passes/MemoryPacking.cpp b/src/passes/MemoryPacking.cpp
index 1d214abdc..c47516485 100644
--- a/src/passes/MemoryPacking.cpp
+++ b/src/passes/MemoryPacking.cpp
@@ -270,6 +270,13 @@ bool MemoryPacking::canSplit(const std::unique_ptr<DataSegment>& segment,
return false;
}
+ if (segment->data.empty()) {
+ // Ignore empty segments, leaving them in place. We may not need them, but
+ // leave that for RemoveUnusedModuleElements to decide (as they may trap
+ // during startup if out of bounds, which is an effect).
+ return false;
+ }
+
for (auto* referrer : referrers) {
if (auto* curr = referrer->dynCast<MemoryInit>()) {
if (segment->isPassive) {
diff --git a/test/lit/passes/memory-packing_all-features.wast b/test/lit/passes/memory-packing_all-features.wast
index cf6c2aeef..42e21e32c 100644
--- a/test/lit/passes/memory-packing_all-features.wast
+++ b/test/lit/passes/memory-packing_all-features.wast
@@ -18,9 +18,12 @@
;; CHECK: (memory $0 2048 2048)
(memory $0 2048 2048)
(import "env" "memoryBase" (global $memoryBase i32))
- (data (i32.const 4066) "") ;; empty
+ (data (i32.const 4066) "") ;; empty; leave it as is
+ ;; (remove-unused-module-elements handles such
+ ;; things, taking into account possible traps etc.)
)
+;; CHECK: (data $0 (i32.const 4066) "")
(module
;; CHECK: (import "env" "memoryBase" (global $memoryBase i32))
@@ -2319,6 +2322,8 @@
(memory $0 1 1 shared)
(data (i32.const 0) "")
(data "foo")
+ ;; CHECK: (data $0 (i32.const 0) "")
+
;; CHECK: (data $1 "foo")
;; CHECK: (func $0 (type $0)