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