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