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