comparison clang/test/CodeGen/switch.c @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children c4bab56944e8
comparison
equal deleted inserted replaced
173:0572611fdcc8 207:2e18cbf3894f
61 j = 5; break; 61 j = 5; break;
62 } 62 }
63 return j; 63 return j;
64 } 64 }
65 65
66 // CHECK-LABEL: define i32 @foo4t() 66 // CHECK-LABEL: define{{.*}} i32 @foo4t()
67 // CHECK: ret i32 376 67 // CHECK: ret i32 376
68 // CHECK: } 68 // CHECK: }
69 int foo4t() { 69 int foo4t() {
70 // 111 + 1 + 222 + 42 = 376 70 // 111 + 1 + 222 + 42 = 376
71 return foo4(111) + foo4(99) + foo4(222) + foo4(601); 71 return foo4(111) + foo4(99) + foo4(222) + foo4(601);
72 } 72 }
73 73
74 // CHECK-LABEL: define void @foo5() 74 // CHECK-LABEL: define{{.*}} void @foo5()
75 // CHECK-NOT: switch 75 // CHECK-NOT: switch
76 // CHECK: } 76 // CHECK: }
77 void foo5(){ 77 void foo5(){
78 switch(0){ 78 switch(0){
79 default: 79 default:
81 81
82 } 82 }
83 } 83 }
84 } 84 }
85 85
86 // CHECK-LABEL: define void @foo6() 86 // CHECK-LABEL: define{{.*}} void @foo6()
87 // CHECK-NOT: switch 87 // CHECK-NOT: switch
88 // CHECK: } 88 // CHECK: }
89 void foo6(){ 89 void foo6(){
90 switch(0){ 90 switch(0){
91 } 91 }
92 } 92 }
93 93
94 // CHECK-LABEL: define void @foo7() 94 // CHECK-LABEL: define{{.*}} void @foo7()
95 // CHECK-NOT: switch 95 // CHECK-NOT: switch
96 // CHECK: } 96 // CHECK: }
97 void foo7(){ 97 void foo7(){
98 switch(0){ 98 switch(0){
99 foo7(); 99 foo7();
100 } 100 }
101 } 101 }
102 102
103 103
104 // CHECK-LABEL: define i32 @f8( 104 // CHECK-LABEL: define{{.*}} i32 @f8(
105 // CHECK: ret i32 3 105 // CHECK: ret i32 3
106 // CHECK: } 106 // CHECK: }
107 int f8(unsigned x) { 107 int f8(unsigned x) {
108 switch(x) { 108 switch(x) {
109 default: 109 default:
113 } 113 }
114 } 114 }
115 115
116 // Ensure that default after a case range is not ignored. 116 // Ensure that default after a case range is not ignored.
117 // 117 //
118 // CHECK-LABEL: define i32 @f9() 118 // CHECK-LABEL: define{{.*}} i32 @f9()
119 // CHECK: ret i32 10 119 // CHECK: ret i32 10
120 // CHECK: } 120 // CHECK: }
121 static int f9_0(unsigned x) { 121 static int f9_0(unsigned x) {
122 switch(x) { 122 switch(x) {
123 case 10 ... 0xFFFFFFFF: 123 case 10 ... 0xFFFFFFFF:
132 132
133 // Ensure that this doesn't compile to infinite loop in g() due to 133 // Ensure that this doesn't compile to infinite loop in g() due to
134 // miscompilation of fallthrough from default to a (tested) case 134 // miscompilation of fallthrough from default to a (tested) case
135 // range. 135 // range.
136 // 136 //
137 // CHECK-LABEL: define i32 @f10() 137 // CHECK-LABEL: define{{.*}} i32 @f10()
138 // CHECK: ret i32 10 138 // CHECK: ret i32 10
139 // CHECK: } 139 // CHECK: }
140 static int f10_0(unsigned x) { 140 static int f10_0(unsigned x) {
141 switch(x) { 141 switch(x) {
142 default: 142 default:
151 return 10; 151 return 10;
152 } 152 }
153 153
154 // This generated incorrect code because of poor switch chaining. 154 // This generated incorrect code because of poor switch chaining.
155 // 155 //
156 // CHECK-LABEL: define i32 @f11( 156 // CHECK-LABEL: define{{.*}} i32 @f11(
157 // CHECK: ret i32 3 157 // CHECK: ret i32 3
158 // CHECK: } 158 // CHECK: }
159 int f11(int x) { 159 int f11(int x) {
160 switch(x) { 160 switch(x) {
161 default: 161 default:
165 } 165 }
166 } 166 }
167 167
168 // This just asserted because of the way case ranges were calculated. 168 // This just asserted because of the way case ranges were calculated.
169 // 169 //
170 // CHECK-LABEL: define i32 @f12( 170 // CHECK-LABEL: define{{.*}} i32 @f12(
171 // CHECK: ret i32 3 171 // CHECK: ret i32 3
172 // CHECK: } 172 // CHECK: }
173 int f12(int x) { 173 int f12(int x) {
174 switch (x) { 174 switch (x) {
175 default: 175 default:
179 } 179 }
180 } 180 }
181 181
182 // Make sure return is not constant (if empty range is skipped or miscompiled) 182 // Make sure return is not constant (if empty range is skipped or miscompiled)
183 // 183 //
184 // CHECK-LABEL: define i32 @f13( 184 // CHECK-LABEL: define{{.*}} i32 @f13(
185 // CHECK: ret i32 % 185 // CHECK: ret i32 %
186 // CHECK: } 186 // CHECK: }
187 int f13(unsigned x) { 187 int f13(unsigned x) {
188 switch(x) { 188 switch(x) {
189 case 2: 189 case 2: