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 // To make it easier to follow the tests: 18 // - all interfaces defined in this file extend InterfaceSuper (except InterfaceOtherSuper) 19 // - all classes defined in this file extend ClassSuper (except ClassOtherSuper) 20 21 interface InterfaceSuper {} 22 interface InterfaceOtherSuper {} 23 24 interface InterfaceA extends InterfaceSuper {} 25 interface InterfaceB extends InterfaceSuper {} 26 interface InterfaceExtendsA extends InterfaceA {} 27 interface InterfaceExtendsB extends InterfaceB {} 28 29 class ClassSuper {} 30 class ClassOtherSuper {} 31 32 class ClassA extends ClassSuper {} 33 class ClassB extends ClassSuper {} 34 class ClassExtendsA extends ClassA {} 35 class ClassExtendsB extends ClassB {} 36 37 class ClassImplementsInterfaceA extends ClassSuper implements InterfaceA {} 38 39 public class Main { 40 41 /// CHECK-START: java.lang.Object Main.testMergeNullContant(boolean) builder (after) 42 /// CHECK: <<Phi:l\d+>> Phi klass:Main 43 /// CHECK: Return [<<Phi>>] testMergeNullContant(boolean cond)44 private Object testMergeNullContant(boolean cond) { 45 return cond ? null : new Main(); 46 } 47 48 /// CHECK-START: java.lang.Object Main.testMergeClasses(boolean, ClassExtendsA, ClassExtendsB) builder (after) 49 /// CHECK: <<Phi:l\d+>> Phi klass:ClassSuper 50 /// CHECK: Return [<<Phi>>] testMergeClasses(boolean cond, ClassExtendsA a, ClassExtendsB b)51 private Object testMergeClasses(boolean cond, ClassExtendsA a, ClassExtendsB b) { 52 // Different classes, have a common super type. 53 return cond ? a : b; 54 } 55 56 /// CHECK-START: java.lang.Object Main.testMergeClasses(boolean, ClassExtendsA, ClassSuper) builder (after) 57 /// CHECK: <<Phi:l\d+>> Phi klass:ClassSuper 58 /// CHECK: Return [<<Phi>>] testMergeClasses(boolean cond, ClassExtendsA a, ClassSuper b)59 private Object testMergeClasses(boolean cond, ClassExtendsA a, ClassSuper b) { 60 // Different classes, one is the super type of the other. 61 return cond ? a : b; 62 } 63 64 /// CHECK-START: java.lang.Object Main.testMergeClasses(boolean, ClassSuper, ClassSuper) builder (after) 65 /// CHECK: <<Phi:l\d+>> Phi klass:ClassSuper 66 /// CHECK: Return [<<Phi>>] testMergeClasses(boolean cond, ClassSuper a, ClassSuper b)67 private Object testMergeClasses(boolean cond, ClassSuper a, ClassSuper b) { 68 // Same classes. 69 return cond ? a : b; 70 } 71 72 /// CHECK-START: java.lang.Object Main.testMergeClasses(boolean, ClassOtherSuper, ClassSuper) builder (after) 73 /// CHECK: <<Phi:l\d+>> Phi klass:java.lang.Object 74 /// CHECK: Return [<<Phi>>] testMergeClasses(boolean cond, ClassOtherSuper a, ClassSuper b)75 private Object testMergeClasses(boolean cond, ClassOtherSuper a, ClassSuper b) { 76 // Different classes, have Object as the common super type. 77 return cond ? a : b; 78 } 79 80 /// CHECK-START: java.lang.Object Main.testMergeClassWithInterface(boolean, ClassImplementsInterfaceA, InterfaceSuper) builder (after) 81 /// CHECK: <<Phi:l\d+>> Phi klass:InterfaceSuper 82 /// CHECK: Return [<<Phi>>] testMergeClassWithInterface(boolean cond, ClassImplementsInterfaceA a, InterfaceSuper b)83 private Object testMergeClassWithInterface(boolean cond, ClassImplementsInterfaceA a, InterfaceSuper b) { 84 // Class implements interface. 85 return cond ? a : b; 86 } 87 88 /// CHECK-START: java.lang.Object Main.testMergeClassWithInterface(boolean, ClassSuper, InterfaceSuper) builder (after) 89 /// CHECK: <<Phi:l\d+>> Phi klass:java.lang.Object 90 /// CHECK: Return [<<Phi>>] testMergeClassWithInterface(boolean cond, ClassSuper a, InterfaceSuper b)91 private Object testMergeClassWithInterface(boolean cond, ClassSuper a, InterfaceSuper b) { 92 // Class doesn't implement interface. 93 return cond ? a : b; 94 } 95 96 /// CHECK-START: java.lang.Object Main.testMergeInterfaces(boolean, InterfaceExtendsA, InterfaceSuper) builder (after) 97 /// CHECK: <<Phi:l\d+>> Phi klass:InterfaceSuper 98 /// CHECK: Return [<<Phi>>] testMergeInterfaces(boolean cond, InterfaceExtendsA a, InterfaceSuper b)99 private Object testMergeInterfaces(boolean cond, InterfaceExtendsA a, InterfaceSuper b) { 100 // Different Interfaces, one implements the other. 101 return cond ? a : b; 102 } 103 104 /// CHECK-START: java.lang.Object Main.testMergeInterfaces(boolean, InterfaceSuper, InterfaceSuper) builder (after) 105 /// CHECK: <<Phi:l\d+>> Phi klass:InterfaceSuper 106 /// CHECK: Return [<<Phi>>] testMergeInterfaces(boolean cond, InterfaceSuper a, InterfaceSuper b)107 private Object testMergeInterfaces(boolean cond, InterfaceSuper a, InterfaceSuper b) { 108 // Same interfaces. 109 return cond ? a : b; 110 } 111 112 /// CHECK-START: java.lang.Object Main.testMergeInterfaces(boolean, InterfaceExtendsA, InterfaceExtendsB) builder (after) 113 /// CHECK: <<Phi:l\d+>> Phi klass:java.lang.Object 114 /// CHECK: Return [<<Phi>>] testMergeInterfaces(boolean cond, InterfaceExtendsA a, InterfaceExtendsB b)115 private Object testMergeInterfaces(boolean cond, InterfaceExtendsA a, InterfaceExtendsB b) { 116 // Different Interfaces, have a common super type. 117 return cond ? a : b; 118 } 119 120 /// CHECK-START: java.lang.Object Main.testMergeInterfaces(boolean, InterfaceSuper, InterfaceOtherSuper) builder (after) 121 /// CHECK: <<Phi:l\d+>> Phi klass:java.lang.Object 122 /// CHECK: Return [<<Phi>>] testMergeInterfaces(boolean cond, InterfaceSuper a, InterfaceOtherSuper b)123 private Object testMergeInterfaces(boolean cond, InterfaceSuper a, InterfaceOtherSuper b) { 124 // Different interfaces. 125 return cond ? a : b; 126 } 127 main(String[] args)128 public static void main(String[] args) { 129 } 130 } 131