Skip to content

Commit 00a038e

Browse files
marc-chevalierchhagedorn
authored andcommitted
8353341: C2: removal of a Mod[DF]Node crashes when the node is already dead
Reviewed-by: thartmann, chagedorn
1 parent bd74922 commit 00a038e

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

src/hotspot/share/opto/divnode.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,8 @@ Node* ModFNode::Ideal(PhaseGVN* phase, bool can_reshape) {
15181518
PhaseIterGVN* igvn = phase->is_IterGVN();
15191519

15201520
bool result_is_unused = proj_out_or_null(TypeFunc::Parms) == nullptr;
1521-
if (result_is_unused) {
1521+
bool not_dead = proj_out_or_null(TypeFunc::Control) != nullptr;
1522+
if (result_is_unused && not_dead) {
15221523
return replace_with_con(igvn, TypeF::make(0.));
15231524
}
15241525

@@ -1569,7 +1570,8 @@ Node* ModDNode::Ideal(PhaseGVN* phase, bool can_reshape) {
15691570
PhaseIterGVN* igvn = phase->is_IterGVN();
15701571

15711572
bool result_is_unused = proj_out_or_null(TypeFunc::Parms) == nullptr;
1572-
if (result_is_unused) {
1573+
bool not_dead = proj_out_or_null(TypeFunc::Control) != nullptr;
1574+
if (result_is_unused && not_dead) {
15731575
return replace_with_con(igvn, TypeD::make(0.));
15741576
}
15751577

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2025, 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+
package compiler.c2.irTests;
24+
25+
import compiler.lib.ir_framework.*;
26+
27+
/*
28+
* @test
29+
* @bug 8353341
30+
* @summary Test that Ideal transformations of Mod[DF]Node are not crashing
31+
* when control proj is absent, and the node is still removed.
32+
* @library /test/lib /
33+
* @run driver compiler.c2.irTests.FPModWithoutControlProj
34+
*/
35+
public class FPModWithoutControlProj {
36+
static int y;
37+
static public boolean flag;
38+
static int iArr[];
39+
40+
public static void main(String[] args) {
41+
TestFramework.runWithFlags("-XX:+StressIGVN");
42+
}
43+
44+
@Run(test = {"testD", "testF"})
45+
public void runMethod() {
46+
testD();
47+
testF();
48+
}
49+
50+
@Test
51+
@IR(failOn = {IRNode.MOD_D, IRNode.MOD_F})
52+
public void testD() {
53+
int x = 243;
54+
double f1 = 119.303D, f2 = 2.637D;
55+
56+
for (int i11 = 0; i11 < 100; i11++) {
57+
if (flag) {
58+
} else if (flag) {
59+
do {
60+
for (f2 = 3; ; f2--) {
61+
if (f2 % 3 == 1) {
62+
x -= y;
63+
}
64+
iArr[1] += 5;
65+
}
66+
} while (f1 < 234);
67+
}
68+
}
69+
}
70+
71+
@Test
72+
@IR(failOn = {IRNode.MOD_D, IRNode.MOD_F})
73+
public void testF() {
74+
int x = 243;
75+
float f1 = 119.303F, f2 = 2.637F;
76+
77+
for (int i11 = 0; i11 < 100; i11++) {
78+
if (flag) {
79+
} else if (flag) {
80+
do {
81+
for (f2 = 3; ; f2--) {
82+
if (f2 % 3 == 1) {
83+
x -= y;
84+
}
85+
iArr[1] += 5;
86+
}
87+
} while (f1 < 234);
88+
}
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)