summaryrefslogtreecommitdiff
path: root/mlir/test/Dialect/ControlFlow/invalid.mlir
blob: 0a71c62ec31af06fff9bc308483d624a369499e7 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// RUN: mlir-opt -verify-diagnostics -split-input-file %s

func.func @switch_missing_case_value(%flag : i32, %caseOperand : i32) {
  cf.switch %flag : i32, [
    default: ^bb1(%caseOperand : i32),
    45: ^bb2(%caseOperand : i32),
    // expected-error@+1 {{expected integer value}}
    : ^bb3(%caseOperand : i32)
  ]

  ^bb1(%bb1arg : i32):
    return
  ^bb2(%bb2arg : i32):
    return
  ^bb3(%bb3arg : i32):
    return
}

// -----

func.func @switch_wrong_type_case_value(%flag : i32, %caseOperand : i32) {
  cf.switch %flag : i32, [
    default: ^bb1(%caseOperand : i32),
    // expected-error@+1 {{expected integer value}}
    "hello": ^bb2(%caseOperand : i32)
  ]

  ^bb1(%bb1arg : i32):
    return
  ^bb2(%bb2arg : i32):
    return
  ^bb3(%bb3arg : i32):
    return
}

// -----

func.func @switch_missing_comma(%flag : i32, %caseOperand : i32) {
  cf.switch %flag : i32, [
    default: ^bb1(%caseOperand : i32),
    // expected-error@+1 {{expected ']'}}
    45: ^bb2(%caseOperand : i32)
    43: ^bb3(%caseOperand : i32)
  ]

  ^bb1(%bb1arg : i32):
    return
  ^bb2(%bb2arg : i32):
    return
  ^bb3(%bb3arg : i32):
    return
}

// -----

func.func @switch_missing_default(%flag : i32, %caseOperand : i32) {
  cf.switch %flag : i32, [
    // expected-error@+1 {{expected 'default'}}
    45: ^bb2(%caseOperand : i32)
    43: ^bb3(%caseOperand : i32)
  ]

  ^bb1(%bb1arg : i32):
    return
  ^bb2(%bb2arg : i32):
    return
  ^bb3(%bb3arg : i32):
    return
}

// -----

// CHECK-LABEL: func @wrong_weights_number
func.func @wrong_weights_number(%cond: i1) {
  // expected-error@+1 {{expects number of branch weights to match number of successors: 1 vs 2}}
  cf.cond_br %cond weights([100]), ^bb1, ^bb2
  ^bb1:
    return
  ^bb2:
    return
}

// -----

// CHECK-LABEL: func @zero_weights
func.func @wrong_total_weight(%cond: i1) {
  // expected-error@+1 {{branch weights cannot all be zero}}
  cf.cond_br %cond weights([0, 0]), ^bb1, ^bb2
  ^bb1:
    return
  ^bb2:
    return
}