Skip to content

Commit

Permalink
Fix #5138. jruby > 9.1.13.0 crashing on bundler when certain jvm flag…
Browse files Browse the repository at this point in the history
…s are

enabled.

Better title would be CFG merges and deletes a BB other BBs still think they
are pointing to.

This seems reasonable to me at the moment and I want to land so if someone is
enterprising they can try and find more problems.  I will have people look at
this.
  • Loading branch information
enebo committed Apr 14, 2018
1 parent f25b8be commit 3c599d4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/ir/instructions/JumpInstr.java
Expand Up @@ -16,6 +16,10 @@ public Label getJumpTarget() {
return (Label) getOperand1();
}

public void setJumpTarget(Label target) {
setOperand1(target);
}

@Override
public Instr clone(CloneInfo ii) {
return new JumpInstr(ii.getRenamedLabel(getJumpTarget()));
Expand Down
Expand Up @@ -7,4 +7,5 @@
*/
public interface JumpTargetInstr {
Label getJumpTarget();
void setJumpTarget(Label target);
}
Expand Up @@ -34,6 +34,10 @@ public void setOperand(int i, Operand operand) {
}
}

public void setJumpTarget(Label target) {
this.jumpTarget = target;
}

public Label getJumpTarget() {
return jumpTarget;
}
Expand Down
Expand Up @@ -38,6 +38,10 @@ public void setOperand(int i, Operand operand) {
}
}

public void setJumpTarget(Label target) {
this.jumpTarget = target;
}

public Label getJumpTarget() {
return jumpTarget;
}
Expand Down
14 changes: 13 additions & 1 deletion core/src/main/java/org/jruby/ir/representations/CFG.java
Expand Up @@ -2,7 +2,6 @@

import org.jruby.dirgra.DirectedGraph;
import org.jruby.dirgra.Edge;
import org.jruby.ir.IRClosure;
import org.jruby.ir.IRManager;
import org.jruby.ir.IRScope;
import org.jruby.ir.Operation;
Expand Down Expand Up @@ -476,6 +475,19 @@ private boolean mergeBBs(BasicBlock a, BasicBlock b) {
addEdge(a, e.getDestination().getData(), e.getType());
}

// Move all incoming edges of b to be incoming edges of a.
for (Edge<BasicBlock> e : getIncomingEdges(b)) {
BasicBlock fixupBB = e.getSource().getData();
removeEdge(fixupBB, b);
addEdge(fixupBB, a, e.getType());

// a -fall-through->b handled above. Any jumps to b must be pointed to a's label.
Instr fixupLastInstr = fixupBB.getLastInstr();
if (fixupLastInstr instanceof JumpTargetInstr) {
((JumpTargetInstr) fixupLastInstr).setJumpTarget(a.getLabel());
}
}

// Delete bb
removeBB(b);

Expand Down

0 comments on commit 3c599d4

Please sign in to comment.