Skip to content

Commit

Permalink
Check for self-cycles on non-loop phis.
Browse files Browse the repository at this point in the history
(cherry picked from commit 3f8a6d5)
  • Loading branch information
gergo- authored and rmosaner committed Jan 8, 2025
1 parent 2bdca22 commit 3b0c36a
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -98,13 +113,15 @@ 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);
}
values().set(i, x);
}

public void setValueAt(int i, ValueNode x) {
verifyNoIllegalSelfLoop(x);
values().set(i, x);
}

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 3b0c36a

Please sign in to comment.