Skip to content

Commit 4a9cc8a

Browse files
enothumTobiHartmann
authored andcommittedJun 20, 2023
8309266: C2: assert(final_con == (jlong)final_int) failed: final value should be integer
Reviewed-by: roland, chagedorn
1 parent 4e4e586 commit 4a9cc8a

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed
 

‎src/hotspot/share/opto/loopnode.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -2311,8 +2311,14 @@ const Type* LoopLimitNode::Value(PhaseGVN* phase) const {
23112311
int final_int = (int)final_con;
23122312
// The final value should be in integer range since the loop
23132313
// is counted and the limit was checked for overflow.
2314-
assert(final_con == (jlong)final_int, "final value should be integer");
2315-
return TypeInt::make(final_int);
2314+
// Assert checks for overflow only if all input nodes are ConINodes, as during CCP
2315+
// there might be a temporary overflow from PhiNodes see JDK-8309266
2316+
assert((in(Init)->is_ConI() && in(Limit)->is_ConI() && in(Stride)->is_ConI()) ? final_con == (jlong)final_int : true, "final value should be integer");
2317+
if (final_con == (jlong)final_int) {
2318+
return TypeInt::make(final_int);
2319+
} else {
2320+
return bottom_type();
2321+
}
23162322
}
23172323

23182324
return bottom_type(); // TypeInt::INT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2023, 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 8309266
27+
* @summary Integer overflow in LoopLimit::Value during PhaseCCP::analyze, triggered by the Phi Node from "flag ? Integer.MAX_VALUE : 1000"
28+
* @run main/othervm -Xbatch -XX:CompileOnly=compiler.loopopts.TestLoopLimitOverflowDuringCCP::* compiler.loopopts.TestLoopLimitOverflowDuringCCP
29+
*/
30+
31+
package compiler.loopopts;
32+
33+
public class TestLoopLimitOverflowDuringCCP {
34+
static boolean flag;
35+
36+
public static void main(String[] strArr) {
37+
for (int i = 0; i < 10000; i++) {
38+
flag = !flag;
39+
test();
40+
}
41+
}
42+
43+
public static void test() {
44+
int limit = flag ? Integer.MAX_VALUE : 1000;
45+
int i = 0;
46+
while (i < limit) {
47+
i += 3;
48+
if (flag) {
49+
return;
50+
}
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)
Please sign in to comment.