diff options
-rw-r--r-- | src/passes/MemoryPacking.cpp | 18 | ||||
-rw-r--r-- | test/passes/memory-packing_all-features.txt | 25 | ||||
-rw-r--r-- | test/passes/memory-packing_all-features.wast | 8 |
3 files changed, 40 insertions, 11 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; } } diff --git a/test/passes/memory-packing_all-features.txt b/test/passes/memory-packing_all-features.txt index 1c8244c16..5f6c5dacc 100644 --- a/test/passes/memory-packing_all-features.txt +++ b/test/passes/memory-packing_all-features.txt @@ -22,15 +22,26 @@ (type $none_=>_none (func)) (memory $0 1 1) (func $foo (; 0 ;) - (drop - (i32.const 0) - ) - (drop - (i32.const 0) + (if + (i32.or + (i32.gt_u + (i32.const 0) + (memory.size) + ) + (i32.or + (i32.const 0) + (i32.const 0) + ) + ) + (unreachable) ) + ) + (func $bar (; 1 ;) (drop - (i32.const 0) + (loop $loop-in (result i32) + (nop) + (i32.const 42) + ) ) - (unreachable) ) ) diff --git a/test/passes/memory-packing_all-features.wast b/test/passes/memory-packing_all-features.wast index c8babf97c..edaba9f11 100644 --- a/test/passes/memory-packing_all-features.wast +++ b/test/passes/memory-packing_all-features.wast @@ -27,4 +27,12 @@ (i32.const 0) ) ) + (func $bar + (drop + (loop (result i32) + (data.drop 0) + (i32.const 42) + ) + ) + ) ) |