committed by
Jakob Stoklund Olesen
parent
79d8aa366d
commit
591f6c1632
97
cranelift/filetests/verifier/type_check.cton
Normal file
97
cranelift/filetests/verifier/type_check.cton
Normal file
@@ -0,0 +1,97 @@
|
||||
test verifier
|
||||
|
||||
function %entry_block_signature_mismatch(i32) {
|
||||
ebb0: ; error: entry block arguments must match function signature
|
||||
return
|
||||
}
|
||||
|
||||
function %entry_block_arg_type(i32) {
|
||||
ebb0(v0: f32): ; error: entry block argument 0 expected to have type i32, got f32
|
||||
return
|
||||
}
|
||||
|
||||
function %incorrect_arg_type(i32, b1) -> i32 {
|
||||
ebb0(v0: i32, v1: b1):
|
||||
v2 = iadd v0, v1 ; error: arg 1 (v1) has type b1, expected i32
|
||||
return v2
|
||||
}
|
||||
|
||||
function %incorrect_return_type() -> f32 {
|
||||
ebb0:
|
||||
v0 = iconst.i32 1
|
||||
return v0 ; error: arg 0 (v0) has type i32, must match function signature of f32
|
||||
}
|
||||
|
||||
function %too_many_return_values() {
|
||||
ebb0:
|
||||
v0 = iconst.i32 1
|
||||
return v0 ; error: arguments of return must match function signature
|
||||
}
|
||||
|
||||
function %too_few_return_values() -> f32, i64 {
|
||||
ebb0:
|
||||
return ; error: arguments of return must match function signature
|
||||
}
|
||||
|
||||
function %type_mismatch_controlling_variable() {
|
||||
ebb0:
|
||||
v0 = iconst.i32 5
|
||||
v1 = iconst.i64 6
|
||||
v2 = iadd v0, v1 ; error: arg 1 (v1) has type i64, expected i32
|
||||
return
|
||||
}
|
||||
|
||||
function %fn_call_too_few_args() {
|
||||
fn2 = function %great_fn(i32, f32)
|
||||
ebb0:
|
||||
call fn2() ; error: mismatched argument count, got 0, expected 2
|
||||
return
|
||||
}
|
||||
|
||||
function %fn_call_too_many_args() {
|
||||
fn5 = function %best_fn()
|
||||
ebb0:
|
||||
v0 = iconst.i64 56
|
||||
v1 = f32const 0.0
|
||||
call fn5(v0, v1) ; error: mismatched argument count, got 2, expected 0
|
||||
return
|
||||
}
|
||||
|
||||
function %fn_call_incorrect_arg_type(i64) {
|
||||
sig9 = (f32)
|
||||
ebb0(v0: i64):
|
||||
v1 = iconst.i32 56
|
||||
call_indirect sig9, v0(v1) ; error: arg 0 (v1) has type i32, expected f32
|
||||
return
|
||||
}
|
||||
|
||||
; TODO: Should we instead just verify that jump tables contain no EBBs that take arguments? This
|
||||
; error doesn't occur if no instruction uses the jump table.
|
||||
function %jump_table_args() {
|
||||
jt1 = jump_table ebb1
|
||||
ebb0:
|
||||
v0 = iconst.i32 0
|
||||
br_table v0, jt1 ; error: takes no arguments, but had target ebb1 with 1 arguments
|
||||
return
|
||||
ebb1(v5: i32):
|
||||
return
|
||||
}
|
||||
|
||||
function %jump_args() {
|
||||
ebb0:
|
||||
v0 = iconst.i16 10
|
||||
v3 = iconst.i64 20
|
||||
jump ebb1(v0, v3) ; error: arg 0 (v0) has type i16, expected i64
|
||||
ebb1(v10: i64, v11: i16):
|
||||
return
|
||||
}
|
||||
|
||||
function %jump_args2() {
|
||||
ebb0:
|
||||
v0 = iconst.i16 10
|
||||
v3 = iconst.i64 20
|
||||
brz v0, ebb1(v0, v3) ; error: arg 0 (v0) has type i16, expected i64
|
||||
jump ebb1(v3, v0)
|
||||
ebb1(v10: i64, v11: i16):
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user