summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/MemoryPacking.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/passes/MemoryPacking.cpp b/src/passes/MemoryPacking.cpp
index d5a8a96dd..18207026a 100644
--- a/src/passes/MemoryPacking.cpp
+++ b/src/passes/MemoryPacking.cpp
@@ -135,10 +135,20 @@ struct MemoryPacking : public Pass {
void visitMemoryInit(MemoryInit* curr) {
if (!getModule()->memory.segments[curr->segment].isPassive) {
Builder builder(*getModule());
- replaceCurrent(builder.blockify(builder.makeDrop(curr->dest),
- builder.makeDrop(curr->offset),
- builder.makeDrop(curr->size),
- builder.makeUnreachable()));
+ // trap if (dest > memory.size | offset | size) != 0
+ replaceCurrent(builder.makeIf(
+ builder.makeBinary(
+ OrInt32,
+ builder.makeBinary(
+ GtUInt32, curr->dest, builder.makeHost(MemorySize, Name(), {})),
+ builder.makeBinary(OrInt32, curr->offset, curr->size)),
+ builder.makeUnreachable()));
+ changed = true;
+ }
+ }
+ void visitDataDrop(DataDrop* curr) {
+ if (!getModule()->memory.segments[curr->segment].isPassive) {
+ ExpressionManipulator::nop(curr);
changed = true;
}
}