Skip to content

Commit

Permalink
8309266: C2: assert(final_con == (jlong)final_int) failed: final valu…
Browse files Browse the repository at this point in the history
…e should be integer

Reviewed-by: roland, chagedorn
  • Loading branch information
enothum authored and TobiHartmann committed Jun 20, 2023
1 parent 4e4e586 commit 4a9cc8a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/hotspot/share/opto/loopnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2311,8 +2311,14 @@ const Type* LoopLimitNode::Value(PhaseGVN* phase) const {
int final_int = (int)final_con;
// The final value should be in integer range since the loop
// is counted and the limit was checked for overflow.
assert(final_con == (jlong)final_int, "final value should be integer");
return TypeInt::make(final_int);
// Assert checks for overflow only if all input nodes are ConINodes, as during CCP
// there might be a temporary overflow from PhiNodes see JDK-8309266
assert((in(Init)->is_ConI() && in(Limit)->is_ConI() && in(Stride)->is_ConI()) ? final_con == (jlong)final_int : true, "final value should be integer");
if (final_con == (jlong)final_int) {
return TypeInt::make(final_int);
} else {
return bottom_type();
}
}

return bottom_type(); // TypeInt::INT
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 8309266
* @summary Integer overflow in LoopLimit::Value during PhaseCCP::analyze, triggered by the Phi Node from "flag ? Integer.MAX_VALUE : 1000"
* @run main/othervm -Xbatch -XX:CompileOnly=compiler.loopopts.TestLoopLimitOverflowDuringCCP::* compiler.loopopts.TestLoopLimitOverflowDuringCCP
*/

package compiler.loopopts;

public class TestLoopLimitOverflowDuringCCP {
static boolean flag;

public static void main(String[] strArr) {
for (int i = 0; i < 10000; i++) {
flag = !flag;
test();
}
}

public static void test() {
int limit = flag ? Integer.MAX_VALUE : 1000;
int i = 0;
while (i < limit) {
i += 3;
if (flag) {
return;
}
}
}
}

1 comment on commit 4a9cc8a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.