xref: /llvm-project/mlir/test/Dialect/ControlFlow/invalid.mlir (revision ad3b358180e8e1d723b790cf5f68264e486c0b1a)
1// RUN: mlir-opt -verify-diagnostics -split-input-file %s
2
3func.func @switch_missing_case_value(%flag : i32, %caseOperand : i32) {
4  cf.switch %flag : i32, [
5    default: ^bb1(%caseOperand : i32),
6    45: ^bb2(%caseOperand : i32),
7    // expected-error@+1 {{expected integer value}}
8    : ^bb3(%caseOperand : i32)
9  ]
10
11  ^bb1(%bb1arg : i32):
12    return
13  ^bb2(%bb2arg : i32):
14    return
15  ^bb3(%bb3arg : i32):
16    return
17}
18
19// -----
20
21func.func @switch_wrong_type_case_value(%flag : i32, %caseOperand : i32) {
22  cf.switch %flag : i32, [
23    default: ^bb1(%caseOperand : i32),
24    // expected-error@+1 {{expected integer value}}
25    "hello": ^bb2(%caseOperand : i32)
26  ]
27
28  ^bb1(%bb1arg : i32):
29    return
30  ^bb2(%bb2arg : i32):
31    return
32  ^bb3(%bb3arg : i32):
33    return
34}
35
36// -----
37
38func.func @switch_missing_comma(%flag : i32, %caseOperand : i32) {
39  cf.switch %flag : i32, [
40    default: ^bb1(%caseOperand : i32),
41    // expected-error@+1 {{expected ']'}}
42    45: ^bb2(%caseOperand : i32)
43    43: ^bb3(%caseOperand : i32)
44  ]
45
46  ^bb1(%bb1arg : i32):
47    return
48  ^bb2(%bb2arg : i32):
49    return
50  ^bb3(%bb3arg : i32):
51    return
52}
53
54// -----
55
56func.func @switch_missing_default(%flag : i32, %caseOperand : i32) {
57  cf.switch %flag : i32, [
58    // expected-error@+1 {{expected 'default'}}
59    45: ^bb2(%caseOperand : i32)
60    43: ^bb3(%caseOperand : i32)
61  ]
62
63  ^bb1(%bb1arg : i32):
64    return
65  ^bb2(%bb2arg : i32):
66    return
67  ^bb3(%bb3arg : i32):
68    return
69}
70