Skip to content

Check maximum alignment #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ml-proto/spec/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions ml-proto/spec/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 20 additions & 7 deletions ml-proto/test/memory.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down