Skip to content

Commit d777c5e

Browse files
committed
Fix OutlineRuntimeChecksPhase NPE check detection
It would mistakenly detect if nodes with null-checks that throw NPEs in the false branch and then produce wrong code
1 parent 2d511cf commit d777c5e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/codegen/phase/OutlineRuntimeChecksPhase.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,15 @@ void replace(CoreProviders providers) {
149149
* {@link ThrowBytecodeExceptionNode}.
150150
*
151151
* @param node A {@link BytecodeExceptionNode} followed immediately by an {@link UnwindNode}
152-
* or a {@link ThrowBytecodeExceptionNode}
152+
* or just a {@link ThrowBytecodeExceptionNode}
153153
*/
154154
static void find(FixedNode node, List<Pattern> patterns) {
155-
boolean isNullCheck = node.predecessor() instanceof BeginNode;
156-
isNullCheck = isNullCheck && node.predecessor().predecessor() instanceof IfNode;
157-
isNullCheck = isNullCheck && singleInput(node.predecessor().predecessor()) instanceof IsNullNode;
155+
Node predecessor = node.predecessor();
156+
boolean isNullCheck = predecessor instanceof BeginNode;
157+
Node secondPredecessor = predecessor.predecessor();
158+
// It has to be an if node where the NPE is thrown in the true-successor
159+
isNullCheck = isNullCheck && secondPredecessor instanceof IfNode ifNode && ifNode.trueSuccessor() == predecessor;
160+
isNullCheck = isNullCheck && singleInput(secondPredecessor) instanceof IsNullNode;
158161

159162
if (isNullCheck) {
160163
NullCheckPattern pattern = new NullCheckPattern(node);

0 commit comments

Comments
 (0)