binaryen
binaryen copied to clipboard
[memory64] Optimization failures on memory.size
wasm-opt fails to process this code with --enable-memory64 -O3:
(module
(type $i32_i64_=>_i32 (func (param i32 i64) (result i32)))
(type $none_=>_none (func))
(memory $0 i64 256 256)
(export "main" (func $0))
(func $0 (param $0 i32) (param $1 i64) (result i32)
(call $1)
(i32.const 0)
)
(func $1
(if
(i32.wrap_i64
(i64.shl
(memory.size)
(i64.const 16)
)
)
(unreachable)
)
)
)
The error is:
[wasm-validator error in function 0] i32 != i64: binary child types must be equal, on
(i64.shl
(memory.size)
(i64.const 16)
)
[wasm-validator error in function 0] i32 != i64: i64 op, on
(i64.shl
(memory.size)
(i64.const 16)
)
[wasm-validator error in function 0] i32 != i64: wrap type must be correct, on
(i32.wrap_i64
(i64.shl
(memory.size)
(i64.const 16)
)
)
Fatal: error after opts
Seems like this is the fix:
diff --git a/src/wasm-delegations-fields.def b/src/wasm-delegations-fields.def
index 3d7504c60..422bb521c 100644
--- a/src/wasm-delegations-fields.def
+++ b/src/wasm-delegations-fields.def
@@ -461,12 +461,16 @@ switch (DELEGATE_ID) {
}
case Expression::Id::MemorySizeId: {
DELEGATE_START(MemorySize);
+ DELEGATE_FIELD_TYPE(MemorySize, type);
+ DELEGATE_FIELD_TYPE(MemorySize, ptrType);
DELEGATE_END(MemorySize);
break;
}
case Expression::Id::MemoryGrowId: {
DELEGATE_START(MemoryGrow);
+ DELEGATE_FIELD_TYPE(MemoryGrow, type);
DELEGATE_FIELD_CHILD(MemoryGrow, delta);
+ DELEGATE_FIELD_TYPE(MemoryGrow, ptrType);
DELEGATE_END(MemoryGrow);
break;
}