• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 {
18 
19   // Workaround for b/18051191.
20   class InnerClass {}
21 
$inline$False()22   static boolean $inline$False() { return false; }
23 
24   // DCE should only merge blocks where the first ends with a Goto.
25   // SSAChecker will fail if the following Throw->TryBoundary blocks are merged.
doNotMergeThrow(String str)26   public static void doNotMergeThrow(String str) {
27     try {
28       throw new Exception(str);
29     } catch (Exception ex) {
30       return;
31     }
32   }
33 
34   // Test deletion of all try/catch blocks. Multiple catch blocks test deletion
35   // where TryBoundary still has exception handler successors after having removed
36   // some already.
37 
38   /// CHECK-START: void Main.testDeadTryCatch(boolean) dead_code_elimination_final (after)
39   /// CHECK-NOT: TryBoundary
40 
41   /// CHECK-START: void Main.testDeadTryCatch(boolean) dead_code_elimination_final (after)
42   /// CHECK: begin_block
43   /// CHECK: begin_block
44   /// CHECK: begin_block
45   /// CHECK-NOT: begin_block
46 
testDeadTryCatch(boolean val)47   public static void testDeadTryCatch(boolean val) {
48     if ($inline$False()) {
49       try {
50         if (val) {
51           throw new ArithmeticException();
52         } else {
53           throw new ArrayIndexOutOfBoundsException();
54         }
55       } catch (ArithmeticException ex) {
56         System.out.println("Unexpected AE catch");
57       } catch (ArrayIndexOutOfBoundsException ex) {
58         System.out.println("Unexpected AIIOB catch");
59       }
60     }
61   }
62 
main(String[] args)63   public static void main(String[] args) {
64 
65   }
66 }