summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClemens Backes <post@clemens-backes.de>2022-03-17 17:03:32 +0100
committerGitHub <noreply@github.com>2022-03-17 16:03:32 +0000
commit86acb00c7095017f8bded15def3c928909099731 (patch)
tree9ca997fdd792f556404065c76185973b57f6b066
parente8cc7965ffdc8926734079f8188408140a04fe7a (diff)
downloadbinaryen-86acb00c7095017f8bded15def3c928909099731.tar.gz
binaryen-86acb00c7095017f8bded15def3c928909099731.tar.bz2
binaryen-86acb00c7095017f8bded15def3c928909099731.zip
[memory64] Keep type of memory.size and memory.grow on copy (#4531)
When copying a MemorySize or MemoryGrow instruction (e.g. for inlining), transfer the memory type also to the copy. Otherwise it will always be i32, even if memory64 should be used. This fixes issue #4530.
-rw-r--r--src/wasm-delegations-fields.def2
-rw-r--r--test/lit/passes/inlining_memory64.wat44
2 files changed, 46 insertions, 0 deletions
diff --git a/src/wasm-delegations-fields.def b/src/wasm-delegations-fields.def
index 3d7504c60..68e23fdd0 100644
--- a/src/wasm-delegations-fields.def
+++ b/src/wasm-delegations-fields.def
@@ -461,11 +461,13 @@ switch (DELEGATE_ID) {
}
case Expression::Id::MemorySizeId: {
DELEGATE_START(MemorySize);
+ DELEGATE_FIELD_TYPE(MemorySize, ptrType);
DELEGATE_END(MemorySize);
break;
}
case Expression::Id::MemoryGrowId: {
DELEGATE_START(MemoryGrow);
+ DELEGATE_FIELD_TYPE(MemoryGrow, ptrType);
DELEGATE_FIELD_CHILD(MemoryGrow, delta);
DELEGATE_END(MemoryGrow);
break;
diff --git a/test/lit/passes/inlining_memory64.wat b/test/lit/passes/inlining_memory64.wat
new file mode 100644
index 000000000..43e77785c
--- /dev/null
+++ b/test/lit/passes/inlining_memory64.wat
@@ -0,0 +1,44 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+
+;; RUN: foreach %s %t wasm-opt --inlining --enable-memory64 -S -o - | filecheck %s
+
+(module
+ ;; CHECK: (type $none_=>_i64 (func (result i64)))
+
+ ;; CHECK: (memory $0 i64 256 256)
+ (memory $0 i64 256 256)
+
+ ;; CHECK: (func $call-size (result i64)
+ ;; CHECK-NEXT: (block $__inlined_func$size (result i64)
+ ;; CHECK-NEXT: (memory.size)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $call-size (result i64)
+ (call $size)
+ )
+
+ (func $size (result i64)
+ ;; Upon inlining this code is copied, and as the memory is 64-bit the copied
+ ;; instruction must remain 64-bit (and not have the default 32-bit size). If
+ ;; we get that wrong then validation would fail here.
+ (memory.size)
+ )
+
+ ;; CHECK: (func $call-grow (result i64)
+ ;; CHECK-NEXT: (block $__inlined_func$grow (result i64)
+ ;; CHECK-NEXT: (memory.grow
+ ;; CHECK-NEXT: (i64.const 1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $call-grow (result i64)
+ ;; As above, but for grow instead of size.
+ (call $grow)
+ )
+
+ (func $grow (result i64)
+ (memory.grow
+ (i64.const 1)
+ )
+ )
+)