1 /* 2 * Copyright (c) 2018, 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 public class ConditionalNodeTest extends GraalCompilerTest { 30 31 @SuppressWarnings("unused") private static int sink0; 32 @SuppressWarnings("unused") private static int sink1; 33 34 @Test test0()35 public void test0() { 36 test("conditionalTest0", 0); 37 test("conditionalTest0", 1); 38 } 39 conditionalTest0(int a)40 public static int conditionalTest0(int a) { 41 int value; 42 if (a == 1) { 43 value = -1; 44 sink1 = 0; 45 } else { 46 value = 6; 47 sink1 = 1; 48 } 49 sink0 = 1; 50 return Math.max(value, 6); 51 } 52 53 @Test test1()54 public void test1() { 55 test("conditionalTest1", 0); 56 test("conditionalTest1", 1); 57 } 58 conditionalTest1(int a)59 public static int conditionalTest1(int a) { 60 int value; 61 if (a == 1) { 62 value = -1; 63 sink1 = 0; 64 } else { 65 value = 6; 66 sink1 = 1; 67 } 68 sink0 = 1; 69 return Math.max(6, value); 70 } 71 72 @Test test2()73 public void test2() { 74 test("conditionalTest2", 0); 75 test("conditionalTest2", 1); 76 } 77 conditionalTest2(int a)78 public static int conditionalTest2(int a) { 79 int value; 80 if (a == 1) { 81 value = -1; 82 sink1 = 0; 83 } else { 84 value = 6; 85 sink1 = 1; 86 } 87 sink0 = 1; 88 return Math.min(value, -1); 89 } 90 91 @Test test3()92 public void test3() { 93 test("conditionalTest3", 0); 94 test("conditionalTest3", 1); 95 } 96 conditionalTest3(int a)97 public static int conditionalTest3(int a) { 98 int value; 99 if (a == 1) { 100 value = -1; 101 sink1 = 0; 102 } else { 103 value = 6; 104 sink1 = 1; 105 } 106 sink0 = 1; 107 return Math.min(-1, value); 108 } 109 } 110