From 3b0c36a2022f056962f2e6f04107172f8bf35616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C3=B6=20Barany?= Date: Fri, 13 Dec 2024 18:08:05 +0100 Subject: [PATCH] Check for self-cycles on non-loop phis. (cherry picked from commit 3f8a6d50893f994f234bdab1f5bc8392b5ee5b17) --- .../src/jdk/graal/compiler/nodes/PhiNode.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/PhiNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/PhiNode.java index 0697d99e8757..80acfca3e478 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/PhiNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/PhiNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2024, 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 @@ -77,9 +77,24 @@ public void setMerge(AbstractMergeNode x) { public boolean verifyNode() { assertTrue(merge() != null, "missing merge"); assertTrue(merge().phiPredecessorCount() == valueCount(), "mismatch between merge predecessor count and phi value count: %d != %d", merge().phiPredecessorCount(), valueCount()); + verifyNoIllegalSelfLoops(); return super.verifyNode(); } + private void verifyNoIllegalSelfLoops() { + if (!(merge instanceof LoopBeginNode)) { + for (int i = 0; i < valueCount(); i++) { + GraalError.guarantee(valueAt(i) != this, "non-loop phi at merge %s must not have a cycle, but value at index %s is itself: %s", merge(), i, valueAt(i)); + } + } + } + + private void verifyNoIllegalSelfLoop(ValueNode value) { + if (!(merge instanceof LoopBeginNode)) { + GraalError.guarantee(value != this, "non-loop phi at merge %s must not have a cycle, but value to be added is itself: %s", merge(), value); + } + } + /** * Get the instruction that produces the value associated with the i'th predecessor of the * merge. @@ -98,6 +113,7 @@ public ValueNode valueAt(int i) { * @param x the new phi input value for the given location */ public void initializeValueAt(int i, ValueNode x) { + verifyNoIllegalSelfLoop(x); while (values().size() <= i) { values().add(null); } @@ -105,6 +121,7 @@ public void initializeValueAt(int i, ValueNode x) { } public void setValueAt(int i, ValueNode x) { + verifyNoIllegalSelfLoop(x); values().set(i, x); } @@ -158,6 +175,7 @@ public void addInput(ValueNode x) { "x", x); assert !(this instanceof ValuePhiNode) || x.stamp(NodeView.DEFAULT).isCompatible(stamp(NodeView.DEFAULT)) : Assertions.errorMessageContext("this", this, "x", x); + verifyNoIllegalSelfLoop(x); values().add(x); }