test/compiler/7110586/Test7110586.java

changeset 0
f90c822e73f8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/compiler/7110586/Test7110586.java	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,132 @@
     1.4 +/*
     1.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +/**
    1.29 + * @test
    1.30 + * @bug 7110586
    1.31 + * @summary C2 generates icorrect results
    1.32 + *
    1.33 + * @run main/othervm -Xbatch Test7110586
    1.34 + */
    1.35 +
    1.36 +public class Test7110586 {
    1.37 +  static int test1() {
    1.38 +    int i = 0;
    1.39 +    for ( ; i < 11; i+=1) {}
    1.40 +    return i;
    1.41 +  }
    1.42 +  static int test2() {
    1.43 +    int i = 0;
    1.44 +    for ( ; i < 11; i+=2) {}
    1.45 +    return i;
    1.46 +  }
    1.47 +  static int test3() {
    1.48 +    int i = 0;
    1.49 +    for ( ; i < 11; i+=3) {}
    1.50 +    return i;
    1.51 +  }
    1.52 +  static int test11() {
    1.53 +    int i = 0;
    1.54 +    for ( ; i < 11; i+=11) {}
    1.55 +    return i;
    1.56 +  }
    1.57 +
    1.58 +  static int testm1() {
    1.59 +    int i = 0;
    1.60 +    for ( ; i > -11; i-=1) {}
    1.61 +    return i;
    1.62 +  }
    1.63 +  static int testm2() {
    1.64 +    int i = 0;
    1.65 +    for ( ; i > -11; i-=2) {}
    1.66 +    return i;
    1.67 +  }
    1.68 +  static int testm3() {
    1.69 +    int i = 0;
    1.70 +    for ( ; i > -11; i-=3) {}
    1.71 +    return i;
    1.72 +  }
    1.73 +  static int testm11() {
    1.74 +    int i = 0;
    1.75 +    for ( ; i > -11; i-=11) {}
    1.76 +    return i;
    1.77 +  }
    1.78 +
    1.79 +  public static void main(String args[]) {
    1.80 +    int x1  = 0;
    1.81 +    int x2  = 0;
    1.82 +    int x3  = 0;
    1.83 +    int x11 = 0;
    1.84 +    int m1  = 0;
    1.85 +    int m2  = 0;
    1.86 +    int m3  = 0;
    1.87 +    int m11 = 0;
    1.88 +    for (int i=0; i<10000; i++) {
    1.89 +      x1  = test1();
    1.90 +      x2  = test2();
    1.91 +      x3  = test3();
    1.92 +      x11 = test11();
    1.93 +      m1  = testm1();
    1.94 +      m2  = testm2();
    1.95 +      m3  = testm3();
    1.96 +      m11 = testm11();
    1.97 +    }
    1.98 +    boolean failed = false;
    1.99 +    if (x1 != 11) {
   1.100 +      System.out.println("ERROR (incr = +1): " + x1 + " != 11");
   1.101 +      failed = true;
   1.102 +    }
   1.103 +    if (x2 != 12) {
   1.104 +      System.out.println("ERROR (incr = +2): " + x2 + " != 12");
   1.105 +      failed = true;
   1.106 +    }
   1.107 +    if (x3 != 12) {
   1.108 +      System.out.println("ERROR (incr = +3): " + x3 + " != 12");
   1.109 +      failed = true;
   1.110 +    }
   1.111 +    if (x11 != 11) {
   1.112 +      System.out.println("ERROR (incr = +11): " + x11 + " != 11");
   1.113 +      failed = true;
   1.114 +    }
   1.115 +    if (m1 != -11) {
   1.116 +      System.out.println("ERROR (incr = -1): " + m1 + " != -11");
   1.117 +      failed = true;
   1.118 +    }
   1.119 +    if (m2 != -12) {
   1.120 +      System.out.println("ERROR (incr = -2): " + m2 + " != -12");
   1.121 +      failed = true;
   1.122 +    }
   1.123 +    if (m3 != -12) {
   1.124 +      System.out.println("ERROR (incr = -3): " + m3 + " != -12");
   1.125 +      failed = true;
   1.126 +    }
   1.127 +    if (m11 != -11) {
   1.128 +      System.out.println("ERROR (incr = -11): " + m11 + " != -11");
   1.129 +      failed = true;
   1.130 +    }
   1.131 +    if (failed) {
   1.132 +      System.exit(97);
   1.133 +    }
   1.134 +  }
   1.135 +}

mercurial