1 /* 2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 package org.graalvm.compiler.core.test; 26 27 import org.junit.Test; 28 29 /** 30 * Collection of tests for {@link org.graalvm.compiler.phases.common.ConditionalEliminationPhase} 31 * including those that triggered bugs in this phase. 32 */ 33 public class ConditionalEliminationTest6 extends ConditionalEliminationTestBase { 34 35 public static final A constA = new A(); 36 public static final B constB = new B(); 37 38 static class A { 39 } 40 41 static class B { 42 } 43 44 @SuppressWarnings("all") 45 public static B reference1Snippet(Object a, B b) { 46 if (a == constA) { 47 return b; 48 } 49 return null; 50 } 51 52 @SuppressWarnings("all") 53 public static B test1Snippet(Object a, B b) { 54 if (a == constA) { 55 if (a == null) { 56 return null; 57 } else { 58 return b; 59 } 60 } 61 return null; 62 } 63 64 @Test 65 public void test1() { 66 testConditionalElimination("test1Snippet", "reference1Snippet"); 67 } 68 69 @SuppressWarnings("all") 70 public static B test2Snippet(Object a, B b) { 71 if (a == constA) { 72 if (a == constB) { 73 return null; 74 } else { 75 return b; 76 } 77 } 78 return null; 79 } 80 81 @Test 82 public void test2() { 83 testConditionalElimination("test2Snippet", "reference1Snippet"); 84 } 85 86 @SuppressWarnings("all") 87 public static B test3Snippet(Object a, B b) { 88 if (a == constA) { 89 if (a == b) { 90 return null; 91 } else { 92 return b; 93 } 94 } 95 return null; 96 } 97 98 @Test 99 public void test3() { 100 testConditionalElimination("test3Snippet", "reference1Snippet"); 101 } 102 }