1 /*
2  * Copyright (c) 2011, 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  * @test
26  * @bug 7110586
27  * @summary C2 generates icorrect results
28  *
29  * @run main/othervm -Xbatch compiler.c2.Test7110586
30  */
31 
32 package compiler.c2;
33 
34 public class Test7110586 {
test1()35   static int test1() {
36     int i = 0;
37     for ( ; i < 11; i+=1) {}
38     return i;
39   }
test2()40   static int test2() {
41     int i = 0;
42     for ( ; i < 11; i+=2) {}
43     return i;
44   }
test3()45   static int test3() {
46     int i = 0;
47     for ( ; i < 11; i+=3) {}
48     return i;
49   }
test11()50   static int test11() {
51     int i = 0;
52     for ( ; i < 11; i+=11) {}
53     return i;
54   }
55 
testm1()56   static int testm1() {
57     int i = 0;
58     for ( ; i > -11; i-=1) {}
59     return i;
60   }
testm2()61   static int testm2() {
62     int i = 0;
63     for ( ; i > -11; i-=2) {}
64     return i;
65   }
testm3()66   static int testm3() {
67     int i = 0;
68     for ( ; i > -11; i-=3) {}
69     return i;
70   }
testm11()71   static int testm11() {
72     int i = 0;
73     for ( ; i > -11; i-=11) {}
74     return i;
75   }
76 
main(String args[])77   public static void main(String args[]) {
78     int x1  = 0;
79     int x2  = 0;
80     int x3  = 0;
81     int x11 = 0;
82     int m1  = 0;
83     int m2  = 0;
84     int m3  = 0;
85     int m11 = 0;
86     for (int i=0; i<10000; i++) {
87       x1  = test1();
88       x2  = test2();
89       x3  = test3();
90       x11 = test11();
91       m1  = testm1();
92       m2  = testm2();
93       m3  = testm3();
94       m11 = testm11();
95     }
96     boolean failed = false;
97     if (x1 != 11) {
98       System.out.println("ERROR (incr = +1): " + x1 + " != 11");
99       failed = true;
100     }
101     if (x2 != 12) {
102       System.out.println("ERROR (incr = +2): " + x2 + " != 12");
103       failed = true;
104     }
105     if (x3 != 12) {
106       System.out.println("ERROR (incr = +3): " + x3 + " != 12");
107       failed = true;
108     }
109     if (x11 != 11) {
110       System.out.println("ERROR (incr = +11): " + x11 + " != 11");
111       failed = true;
112     }
113     if (m1 != -11) {
114       System.out.println("ERROR (incr = -1): " + m1 + " != -11");
115       failed = true;
116     }
117     if (m2 != -12) {
118       System.out.println("ERROR (incr = -2): " + m2 + " != -12");
119       failed = true;
120     }
121     if (m3 != -12) {
122       System.out.println("ERROR (incr = -3): " + m3 + " != -12");
123       failed = true;
124     }
125     if (m11 != -11) {
126       System.out.println("ERROR (incr = -11): " + m11 + " != -11");
127       failed = true;
128     }
129     if (failed) {
130       System.exit(97);
131     }
132   }
133 }
134