blob: 96118f6e6fc3972dae970fb09d992bf6f409b0cc [file] [log] [blame]
Daniel Dunbar600d47e2009-11-20 17:23:39 +00001// RUN: clang-cc -triple i386-unknown-unknown -O3 %s -emit-llvm -o - | FileCheck %s
Devang Patel51b09f22007-10-04 23:45:31 +00002
3int foo(int i) {
4 int j = 0;
5 switch (i) {
Chris Lattnerc69a5812007-11-30 17:44:57 +00006 case -1:
7 j = 1; break;
Daniel Dunbar600d47e2009-11-20 17:23:39 +00008 case 1 :
Devang Patel51b09f22007-10-04 23:45:31 +00009 j = 2; break;
10 case 2:
11 j = 3; break;
12 default:
13 j = 42; break;
14 }
15 j = j + 1;
16 return j;
17}
18
Devang Patel2d79d0f2007-10-05 20:54:07 +000019int foo2(int i) {
20 int j = 0;
21 switch (i) {
Daniel Dunbar600d47e2009-11-20 17:23:39 +000022 case 1 :
Devang Patel2d79d0f2007-10-05 20:54:07 +000023 j = 2; break;
24 case 2 ... 10:
25 j = 3; break;
26 default:
27 j = 42; break;
28 }
29 j = j + 1;
30 return j;
31}
32
Devang Patelc049e4f2007-10-08 20:57:48 +000033int foo3(int i) {
34 int j = 0;
35 switch (i) {
36 default:
37 j = 42; break;
38 case 111:
39 j = 111; break;
40 case 0 ... 100:
41 j = 1; break;
42 case 222:
43 j = 222; break;
44 }
45 return j;
46}
47
48
Daniel Dunbar600d47e2009-11-20 17:23:39 +000049static int foo4(int i) {
Devang Patelc049e4f2007-10-08 20:57:48 +000050 int j = 0;
51 switch (i) {
52 case 111:
53 j = 111; break;
54 case 0 ... 100:
55 j = 1; break;
56 case 222:
57 j = 222; break;
58 default:
59 j = 42; break;
60 case 501 ... 600:
61 j = 5; break;
62 }
63 return j;
64}
Chris Lattner1438b492007-12-01 05:27:33 +000065
Daniel Dunbar600d47e2009-11-20 17:23:39 +000066// CHECK: define i32 @foo4t()
67// CHECK: ret i32 376
68// CHECK: }
69int foo4t() {
70 // 111 + 1 + 222 + 42 = 376
71 return foo4(111) + foo4(99) + foo4(222) + foo4(601);
72}
73
74// CHECK: define void @foo5()
75// CHECK-NOT: switch
76// CHECK: }
Chris Lattner1438b492007-12-01 05:27:33 +000077void foo5(){
78 switch(0){
79 default:
80 if (0) {
81
82 }
83 }
84}
85
Daniel Dunbar600d47e2009-11-20 17:23:39 +000086// CHECK: define void @foo6()
87// CHECK-NOT: switch
88// CHECK: }
Eli Friedmand28a80d2008-05-12 16:08:04 +000089void foo6(){
90 switch(0){
91 }
92}
93
Daniel Dunbar600d47e2009-11-20 17:23:39 +000094// CHECK: define void @foo7()
95// CHECK-NOT: switch
96// CHECK: }
Eli Friedmand28a80d2008-05-12 16:08:04 +000097void foo7(){
98 switch(0){
99 foo7();
100 }
101}
102