diff --git a/ml-proto/spec/check.ml b/ml-proto/spec/check.ml index a64b88f7df..abef23d65b 100644 --- a/ml-proto/spec/check.ml +++ b/ml-proto/spec/check.ml @@ -256,7 +256,8 @@ and check_has_memory c at = and check_memop memop at = require (memop.offset >= 0L) at "negative offset"; require (memop.offset <= 0xffffffffL) at "offset too large"; - require (Lib.Int.is_power_of_two memop.align) at "non-power-of-two alignment"; + require (Lib.Int.is_power_of_two memop.align) at "alignment must be a power of two"; + require (memop.align <= size memop.ty) at "alignment must not be larger than natural" and check_mem_type ty sz at = require (ty = Int64Type || sz <> Memory.Mem32) at "memory size too big" diff --git a/ml-proto/spec/types.ml b/ml-proto/spec/types.ml index 5081be252d..a5ac41d446 100644 --- a/ml-proto/spec/types.ml +++ b/ml-proto/spec/types.ml @@ -4,6 +4,14 @@ type value_type = Int32Type | Int64Type | Float32Type | Float64Type type expr_type = value_type option type func_type = {ins : value_type list; out : expr_type} + +(* Attributes *) + +let size = function + | Int32Type | Float32Type -> 4 + | Int64Type | Float64Type -> 8 + + (* String conversion *) let string_of_value_type = function diff --git a/ml-proto/test/memory.wast b/ml-proto/test/memory.wast index 390717e4cd..def709ba25 100644 --- a/ml-proto/test/memory.wast +++ b/ml-proto/test/memory.wast @@ -48,28 +48,41 @@ ;; Test alignment annotation rules (module (memory 0) (func (i32.load8_u align=2 (i32.const 0)))) (module (memory 0) (func (i32.load16_u align=4 (i32.const 0)))) -(module (memory 0) (func (i32.load align=8 (i32.const 0)))) -(module (memory 0) (func (f32.load align=8 (i32.const 0)))) +(module (memory 0) (func (i32.load align=4 (i32.const 0)))) +(module (memory 0) (func (f32.load align=4 (i32.const 0)))) (assert_invalid (module (memory 0) (func (i64.load align=0 (i32.const 0)))) - "non-power-of-two alignment" + "alignment must be a power of two" ) (assert_invalid (module (memory 0) (func (i64.load align=3 (i32.const 0)))) - "non-power-of-two alignment" + "alignment must be a power of two" ) (assert_invalid (module (memory 0) (func (i64.load align=5 (i32.const 0)))) - "non-power-of-two alignment" + "alignment must be a power of two" ) (assert_invalid (module (memory 0) (func (i64.load align=6 (i32.const 0)))) - "non-power-of-two alignment" + "alignment must be a power of two" ) (assert_invalid (module (memory 0) (func (i64.load align=7 (i32.const 0)))) - "non-power-of-two alignment" + "alignment must be a power of two" +) + +(assert_invalid + (module (memory 0) (func (i64.load align=16 (i32.const 0)))) + "alignment must not be larger than natural" +) +(assert_invalid + (module (memory 0) (func (i64.load align=32 (i32.const 0)))) + "alignment must not be larger than natural" +) +(assert_invalid + (module (memory 0) (func (i32.load align=8 (i32.const 0)))) + "alignment must not be larger than natural" ) (module