1 /*
2  * Copyright (C) 2016 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 
18 /*
19  * A test that checks that the inliner does not inline functions that contain
20  * a loop with no exit.  This because the incremental update to
21  * HLoopInformation done by the inliner does not work with the LinearOrder
22  * computation if the inlined function does not always return.
23  */
24 
25 public class Main {
26 
assertIntEquals(int expected, int result)27   public static void assertIntEquals(int expected, int result) {
28     if (expected != result) {
29       throw new Error("Expected: " + expected + ", found: " + result);
30     }
31   }
32 
$opt$noinline$Function(int x, int y)33   public static int $opt$noinline$Function(int x, int y) {
34     int result;
35     if (x <= y) {
36       result = 42;
37     } else {
38       while (true);
39     }
40     return result;
41   }
42 
43   /// CHECK-START: int Main.callerLoop(int, int) inliner (before)
44   /// CHECK:         InvokeStaticOrDirect method_name:Main.$opt$noinline$Function  loop:{{B\d+}}
45 
46   /// CHECK-START: int Main.callerLoop(int, int) inliner (after)
47   /// CHECK:         InvokeStaticOrDirect method_name:Main.$opt$noinline$Function  loop:{{B\d+}}
48 
callerLoop(int max_x, int max_y)49   public static int callerLoop(int max_x, int max_y) {
50     int total = 0;
51     for (int x = 0; x < max_x; ++x) {
52       total += $opt$noinline$Function(x, max_y);
53     }
54     return total;
55   }
56 
main(String[] args)57   public static void main(String[] args) {
58     assertIntEquals(42, callerLoop(1, 1));
59   }
60 }
61