Skip to content

Commit 86acb00

Browse files
authored
[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.
1 parent e8cc796 commit 86acb00

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/wasm-delegations-fields.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,13 @@ switch (DELEGATE_ID) {
461461
}
462462
case Expression::Id::MemorySizeId: {
463463
DELEGATE_START(MemorySize);
464+
DELEGATE_FIELD_TYPE(MemorySize, ptrType);
464465
DELEGATE_END(MemorySize);
465466
break;
466467
}
467468
case Expression::Id::MemoryGrowId: {
468469
DELEGATE_START(MemoryGrow);
470+
DELEGATE_FIELD_TYPE(MemoryGrow, ptrType);
469471
DELEGATE_FIELD_CHILD(MemoryGrow, delta);
470472
DELEGATE_END(MemoryGrow);
471473
break;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
3+
;; RUN: foreach %s %t wasm-opt --inlining --enable-memory64 -S -o - | filecheck %s
4+
5+
(module
6+
;; CHECK: (type $none_=>_i64 (func (result i64)))
7+
8+
;; CHECK: (memory $0 i64 256 256)
9+
(memory $0 i64 256 256)
10+
11+
;; CHECK: (func $call-size (result i64)
12+
;; CHECK-NEXT: (block $__inlined_func$size (result i64)
13+
;; CHECK-NEXT: (memory.size)
14+
;; CHECK-NEXT: )
15+
;; CHECK-NEXT: )
16+
(func $call-size (result i64)
17+
(call $size)
18+
)
19+
20+
(func $size (result i64)
21+
;; Upon inlining this code is copied, and as the memory is 64-bit the copied
22+
;; instruction must remain 64-bit (and not have the default 32-bit size). If
23+
;; we get that wrong then validation would fail here.
24+
(memory.size)
25+
)
26+
27+
;; CHECK: (func $call-grow (result i64)
28+
;; CHECK-NEXT: (block $__inlined_func$grow (result i64)
29+
;; CHECK-NEXT: (memory.grow
30+
;; CHECK-NEXT: (i64.const 1)
31+
;; CHECK-NEXT: )
32+
;; CHECK-NEXT: )
33+
;; CHECK-NEXT: )
34+
(func $call-grow (result i64)
35+
;; As above, but for grow instead of size.
36+
(call $grow)
37+
)
38+
39+
(func $grow (result i64)
40+
(memory.grow
41+
(i64.const 1)
42+
)
43+
)
44+
)

0 commit comments

Comments
 (0)