1 /*
   2  * Copyright (c) 2011, 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 import org.graalvm.compiler.core.test.ea.EATestBase.TestClassInt;
  30 
  31 public class ShortCircuitNodeTest extends GraalCompilerTest {
  32 
  33     @Test
  34     public void test1() {
  35         // only executeActual, to avoid creating profiling information
  36         executeActual(getResolvedJavaMethod("test1Snippet"), 1, 2);
  37     }
  38 
  39     public static final TestClassInt field = null;
  40     public static TestClassInt field2 = null;
  41 
  42     @SuppressWarnings("unused")
  43     public static void test1Snippet(int a, int b) {
  44         /*
  45          * if a ShortCircuitOrNode is created for the check inside test2, then faulty handling of
  46          * guards can create a cycle in the graph.
  47          */
  48         int v;
  49         if (a == 1) {
  50             if (b != 1) {
  51                 int i = field.x;
  52             }
  53             field2 = null;
  54             v = 0;
  55         } else {
  56             v = 1;
  57         }
  58 
  59         if (test2(v, b)) {
  60             int i = field.x;
  61         }
  62     }
  63 
  64     public static boolean test2(int a, int b) {
  65         return a != 0 || b != 1;
  66     }
  67 }