xref: /aosp_15_r20/art/test/2266-checker-remove-empty-ifs/src/Main.java (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2023 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker public class Main {
main(String[] args)18*795d594fSAndroid Build Coastguard Worker     public static void main(String[] args) {}
$inline$empty()19*795d594fSAndroid Build Coastguard Worker     public static void $inline$empty() {}
$inline$empty2()20*795d594fSAndroid Build Coastguard Worker     public static void $inline$empty2() {}
21*795d594fSAndroid Build Coastguard Worker 
22*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.andBoolean2(boolean, boolean) dead_code_elimination$after_inlining (before)
23*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
24*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
25*795d594fSAndroid Build Coastguard Worker 
26*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.andBoolean2(boolean, boolean) dead_code_elimination$after_inlining (after)
27*795d594fSAndroid Build Coastguard Worker     /// CHECK-NOT: If
andBoolean2(boolean a, boolean b)28*795d594fSAndroid Build Coastguard Worker     public static void andBoolean2(boolean a, boolean b) {
29*795d594fSAndroid Build Coastguard Worker         if (a && b) {
30*795d594fSAndroid Build Coastguard Worker             $inline$empty();
31*795d594fSAndroid Build Coastguard Worker         } else {
32*795d594fSAndroid Build Coastguard Worker             $inline$empty2();
33*795d594fSAndroid Build Coastguard Worker         }
34*795d594fSAndroid Build Coastguard Worker     }
35*795d594fSAndroid Build Coastguard Worker 
36*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.andBoolean3(boolean, boolean, boolean) dead_code_elimination$after_inlining (before)
37*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
38*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
39*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
40*795d594fSAndroid Build Coastguard Worker 
41*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.andBoolean3(boolean, boolean, boolean) dead_code_elimination$after_inlining (after)
42*795d594fSAndroid Build Coastguard Worker     /// CHECK-NOT: If
andBoolean3(boolean a, boolean b, boolean c)43*795d594fSAndroid Build Coastguard Worker     public static void andBoolean3(boolean a, boolean b, boolean c) {
44*795d594fSAndroid Build Coastguard Worker         if (a && b && c) {
45*795d594fSAndroid Build Coastguard Worker             $inline$empty();
46*795d594fSAndroid Build Coastguard Worker         } else {
47*795d594fSAndroid Build Coastguard Worker             $inline$empty2();
48*795d594fSAndroid Build Coastguard Worker         }
49*795d594fSAndroid Build Coastguard Worker     }
50*795d594fSAndroid Build Coastguard Worker 
51*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.andBoolean4(boolean, boolean, boolean, boolean) dead_code_elimination$after_inlining (before)
52*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
53*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
54*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
55*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
56*795d594fSAndroid Build Coastguard Worker 
57*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.andBoolean4(boolean, boolean, boolean, boolean) dead_code_elimination$after_inlining (after)
58*795d594fSAndroid Build Coastguard Worker     /// CHECK-NOT: If
andBoolean4(boolean a, boolean b, boolean c, boolean d)59*795d594fSAndroid Build Coastguard Worker     public static void andBoolean4(boolean a, boolean b, boolean c, boolean d) {
60*795d594fSAndroid Build Coastguard Worker         if (a && b && c && d) {
61*795d594fSAndroid Build Coastguard Worker             $inline$empty();
62*795d594fSAndroid Build Coastguard Worker         } else {
63*795d594fSAndroid Build Coastguard Worker             $inline$empty2();
64*795d594fSAndroid Build Coastguard Worker         }
65*795d594fSAndroid Build Coastguard Worker     }
66*795d594fSAndroid Build Coastguard Worker 
67*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.orBoolean2(boolean, boolean) dead_code_elimination$after_inlining (before)
68*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
69*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
70*795d594fSAndroid Build Coastguard Worker 
71*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.orBoolean2(boolean, boolean) dead_code_elimination$after_inlining (after)
72*795d594fSAndroid Build Coastguard Worker     /// CHECK-NOT: If
orBoolean2(boolean a, boolean b)73*795d594fSAndroid Build Coastguard Worker     public static void orBoolean2(boolean a, boolean b) {
74*795d594fSAndroid Build Coastguard Worker         if (a || b) {
75*795d594fSAndroid Build Coastguard Worker             $inline$empty();
76*795d594fSAndroid Build Coastguard Worker         } else {
77*795d594fSAndroid Build Coastguard Worker             $inline$empty2();
78*795d594fSAndroid Build Coastguard Worker         }
79*795d594fSAndroid Build Coastguard Worker     }
80*795d594fSAndroid Build Coastguard Worker 
81*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.orBoolean3(boolean, boolean, boolean) dead_code_elimination$after_inlining (before)
82*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
83*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
84*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
85*795d594fSAndroid Build Coastguard Worker 
86*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.orBoolean3(boolean, boolean, boolean) dead_code_elimination$after_inlining (after)
87*795d594fSAndroid Build Coastguard Worker     /// CHECK-NOT: If
orBoolean3(boolean a, boolean b, boolean c)88*795d594fSAndroid Build Coastguard Worker     public static void orBoolean3(boolean a, boolean b, boolean c) {
89*795d594fSAndroid Build Coastguard Worker         if (a || b || c) {
90*795d594fSAndroid Build Coastguard Worker             $inline$empty();
91*795d594fSAndroid Build Coastguard Worker         } else {
92*795d594fSAndroid Build Coastguard Worker             $inline$empty2();
93*795d594fSAndroid Build Coastguard Worker         }
94*795d594fSAndroid Build Coastguard Worker     }
95*795d594fSAndroid Build Coastguard Worker 
96*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.orBoolean4(boolean, boolean, boolean, boolean) dead_code_elimination$after_inlining (before)
97*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
98*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
99*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
100*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
101*795d594fSAndroid Build Coastguard Worker 
102*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.orBoolean4(boolean, boolean, boolean, boolean) dead_code_elimination$after_inlining (after)
103*795d594fSAndroid Build Coastguard Worker     /// CHECK-NOT: If
orBoolean4(boolean a, boolean b, boolean c, boolean d)104*795d594fSAndroid Build Coastguard Worker     public static void orBoolean4(boolean a, boolean b, boolean c, boolean d) {
105*795d594fSAndroid Build Coastguard Worker         if (a || b || c || d) {
106*795d594fSAndroid Build Coastguard Worker             $inline$empty();
107*795d594fSAndroid Build Coastguard Worker         } else {
108*795d594fSAndroid Build Coastguard Worker             $inline$empty2();
109*795d594fSAndroid Build Coastguard Worker         }
110*795d594fSAndroid Build Coastguard Worker     }
111*795d594fSAndroid Build Coastguard Worker 
112*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.andInt(int, int, int, int) dead_code_elimination$after_inlining (before)
113*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
114*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
115*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
116*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
117*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
118*795d594fSAndroid Build Coastguard Worker 
119*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.andInt(int, int, int, int) dead_code_elimination$after_inlining (after)
120*795d594fSAndroid Build Coastguard Worker     /// CHECK-NOT: If
andInt(int a, int b, int c, int d)121*795d594fSAndroid Build Coastguard Worker     public static void andInt(int a, int b, int c, int d) {
122*795d594fSAndroid Build Coastguard Worker         if (a <= b && c <= d && a >= 20 && b <= 78 && c >= 50 && d <= 70) {
123*795d594fSAndroid Build Coastguard Worker             $inline$empty();
124*795d594fSAndroid Build Coastguard Worker         } else {
125*795d594fSAndroid Build Coastguard Worker             $inline$empty2();
126*795d594fSAndroid Build Coastguard Worker         }
127*795d594fSAndroid Build Coastguard Worker     }
128*795d594fSAndroid Build Coastguard Worker 
129*795d594fSAndroid Build Coastguard Worker     class MyObject {
130*795d594fSAndroid Build Coastguard Worker         boolean inner;
131*795d594fSAndroid Build Coastguard Worker         boolean inner2;
132*795d594fSAndroid Build Coastguard Worker     }
133*795d594fSAndroid Build Coastguard Worker 
134*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.andObject(Main$MyObject) dead_code_elimination$after_inlining (before)
135*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
136*795d594fSAndroid Build Coastguard Worker     /// CHECK: If
137*795d594fSAndroid Build Coastguard Worker 
138*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.andObject(Main$MyObject) dead_code_elimination$after_inlining (before)
139*795d594fSAndroid Build Coastguard Worker     /// CHECK: InstanceFieldGet
140*795d594fSAndroid Build Coastguard Worker     /// CHECK: InstanceFieldGet
141*795d594fSAndroid Build Coastguard Worker 
142*795d594fSAndroid Build Coastguard Worker     /// CHECK-START: void Main.andObject(Main$MyObject) dead_code_elimination$after_inlining (after)
143*795d594fSAndroid Build Coastguard Worker     /// CHECK-NOT: If
144*795d594fSAndroid Build Coastguard Worker     /// CHECK-NOT: InstanceFieldGet
andObject(MyObject o)145*795d594fSAndroid Build Coastguard Worker     public static void andObject(MyObject o) {
146*795d594fSAndroid Build Coastguard Worker         if (o != null && o.inner && o.inner2) {
147*795d594fSAndroid Build Coastguard Worker             $inline$empty();
148*795d594fSAndroid Build Coastguard Worker         } else {
149*795d594fSAndroid Build Coastguard Worker             $inline$empty2();
150*795d594fSAndroid Build Coastguard Worker         }
151*795d594fSAndroid Build Coastguard Worker     }
152*795d594fSAndroid Build Coastguard Worker }
153