-
Notifications
You must be signed in to change notification settings - Fork 44
/
verifier.mlir
75 lines (64 loc) · 2.47 KB
/
verifier.mlir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// RUN: heir-opt --verify-diagnostics --split-input-file %s
func.func @test_cleartext_type_mismatch(%value: i32, %c1: i32) {
// expected-error@+1 {{If the operand is not secret, it must be the same type as}}
%Z = secret.generic
ins(%value, %c1 : i32, i32) {
^bb0(%clear_value: i64, %clear_c1: i64):
%0 = arith.addi %clear_value, %clear_c1 : i64
secret.yield %0 : i64
} -> (!secret.secret<i64>)
return
}
// -----
func.func @test_secret_type_mismatch(%value: !secret.secret<i32>, %c1: i32) {
// expected-error@+1 {{Type mismatch between block argument 0 of type 'i64' and generic operand of type '!secret.secret<i32>'}}
%Z = secret.generic
ins(%value, %c1 : !secret.secret<i32>, i32) {
^bb0(%clear_value: i64, %clear_c1: i32):
%0 = arith.trunci %clear_value : i64 to i32
%1 = arith.addi %0, %clear_c1 : i32
secret.yield %1 : i32
} -> (!secret.secret<i32>)
return
}
// -----
func.func @test_refers_to_value_outside_block(%value: !secret.secret<i32>) {
%c1 = arith.constant 1 : i32
// expected-error@+1 {{uses a value defined outside the block}}
%Z = secret.generic
ins(%value : !secret.secret<i32>) {
^bb0(%clear_value: i32):
%1 = arith.addi %clear_value, %c1 : i32
secret.yield %1 : i32
} -> (!secret.secret<i32>)
return
}
// -----
func.func @test_refers_to_block_argument_outside_block(%value: !secret.secret<i32>, %c1 : i32) {
// expected-error@+1 {{uses a block argument defined outside the block}}
%Z = secret.generic
ins(%value : !secret.secret<i32>) {
^bb0(%clear_value: i32):
%1 = arith.addi %clear_value, %c1 : i32
secret.yield %1 : i32
} -> (!secret.secret<i32>)
return
}
// -----
func.func @ensure_yield_inside_generic(%value: !secret.secret<i32>) {
// expected-error@+1 {{expects parent op 'secret.generic'}}
secret.yield %value : !secret.secret<i32>
return
}
// -----
func.func @test_yield_type_agrees_with_generic(%value: !secret.secret<i32>) {
%Z = secret.generic
ins(%value : !secret.secret<i32>) {
^bb0(%clear_value: i32):
%1 = arith.addi %clear_value, %clear_value : i32
%2 = arith.extui %1 : i32 to i64
// expected-error@+1 {{If a yield op returns types T, S, ..., then the enclosing generic op must have result types secret.secret<T>, secret.secret<S>, ... But this yield op has operand types: 'i64'; while the enclosing generic op has result types: '!secret.secret<i32>'}}
secret.yield %2 : i64
} -> (!secret.secret<i32>)
return
}