summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-04-07 14:06:10 -0700
committerGitHub <noreply@github.com>2023-04-07 14:06:10 -0700
commit0578862dc5569a4b544800d666458d698536a1a5 (patch)
treee007c518c87ebbdd007a1ecf1a23f789b4f5f5a9 /src
parent642d663d50ee90b19ef4d0c2e92f30585799d8b1 (diff)
downloadbinaryen-0578862dc5569a4b544800d666458d698536a1a5.tar.gz
binaryen-0578862dc5569a4b544800d666458d698536a1a5.tar.bz2
binaryen-0578862dc5569a4b544800d666458d698536a1a5.zip
Fix MemoryPacking handling of array.init_data (#5644)
Do not optimize out or split segments that are referred to array.init_data instructions. Fixes a bug where segments could get optimized out, producing invalid modules. Doing the work to actually split segments used by array.init_data is left for the future. Also fix a latent UBSan failure revealed by the new test case.
Diffstat (limited to 'src')
-rw-r--r--src/passes/MemoryPacking.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/passes/MemoryPacking.cpp b/src/passes/MemoryPacking.cpp
index 5178db3ac..b2798f4b6 100644
--- a/src/passes/MemoryPacking.cpp
+++ b/src/passes/MemoryPacking.cpp
@@ -278,8 +278,8 @@ bool MemoryPacking::canSplit(const std::unique_ptr<DataSegment>& segment,
return false;
}
}
- } else if (referrer->is<ArrayNewSeg>()) {
- // TODO: Split segments referenced by array.new_data instructions.
+ } else if (referrer->is<ArrayNewSeg>() || referrer->is<ArrayInit>()) {
+ // TODO: Split segments referenced by GC instructions.
return false;
}
}
@@ -479,8 +479,10 @@ void MemoryPacking::getSegmentReferrers(Module* module,
referrers[curr->segment].push_back(curr);
}
}
- void doWalkFunction(Function* func) {
- super::doWalkFunction(func);
+ void visitArrayInit(ArrayInit* curr) {
+ if (curr->op == InitData) {
+ referrers[curr->segment].push_back(curr);
+ }
}
} collector(referrers);
collector.walkFunctionInModule(func, module);
@@ -586,7 +588,7 @@ void MemoryPacking::createSplitSegments(
segment->memory,
segment->isPassive,
offset,
- &segment->data[range.start],
+ segment->data.data() + range.start,
range.end - range.start);
curr->hasExplicitName = hasExplicitName;
packed.push_back(std::move(curr));