switch.go
1.07 KB
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
// RUN: llgo -S -emit-llvm -o - %s | FileCheck %s
package foo
// CHECK: switch i32
// CHECK-NEXT: i32 0, label %[[L0:.*]]
// CHECK-NEXT: i32 1, label %[[L1:.*]]
// CHECK-NEXT: i32 2, label %[[L2:.*]]
// CHECK-NEXT: ]
// CHECK: [[L0]]:
// CHECK-NEXT: ret i32 1
// CHECK: [[L1]]:
// CHECK-NEXT: ret i32 2
// CHECK: [[L2]]:
// CHECK-NEXT: ret i32 0
func F1(x int32) int32 {
switch x {
case 0:
return 1
case 1:
return 2
case 2:
return 0
}
panic("unreachable")
}
// CHECK: switch i64
// CHECK-NEXT: i64 0
// CHECK-NEXT: ]
// CHECK: icmp eq i64 {{.*}}, 1
func F2(x int64) bool {
return x == 0 || x == 0 || x == 1
}
// CHECK: switch i64
// CHECK-NEXT: i64 0
// CHECK-NEXT: ]
func F3(x int64) bool {
return x == 0 || x == 0 || x == 0
}
// CHECK: switch i64
// CHECK-NEXT: i64 0
// CHECK-NEXT: i64 1
// CHECK-NEXT: i64 2
// CHECK-NEXT: ]
// CHECK: icmp eq i64 {{.*}}, 3
func F4(x int64) bool {
return x == 0 || x == 1 || x == 2 || x == 3
}
// CHECK-NOT: switch double
func F5(x float64) float64 {
switch x {
case 0:
return 1.0
case 1.0:
return 0
}
panic("unreachable")
}