Program: 149940
Project: 149940
Buggy source:
/** 
 * Make an empty basic block on an edge in the control flow graph, and fix up the control flow graph and IR instructions accordingly. This routine will create the control struture <pre> in -> bb -> out. </pre> <em> Precondition </em>: There is an edge in the control flow graph  from * in -> out.
 * @param in the source of the control flow edge
 * @param out the sink of the control flow edge
 * @param ir the governing IR
 * @return the new basic block bb
 */
public static OPT_BasicBlock makeBlockOnEdge(OPT_BasicBlock in,OPT_BasicBlock out,OPT_IR ir){
  OPT_BasicBlock bb=in.createSubBlock(out.firstInstruction().bcIndex,ir);
  OPT_BasicBlock next=in.nextBasicBlockInCodeOrder();
  if (next == null) {
    ir.cfg.addLastInCodeOrder(bb);
  }
 else {
    ir.cfg.breakCodeOrder(in,next);
    ir.cfg.linkInCodeOrder(in,bb);
    ir.cfg.linkInCodeOrder(bb,next);
  }
  boolean foundGoto=false;
  OPT_BranchOperand target=bb.makeJumpTarget();
  OPT_BranchOperand outTarget=out.makeJumpTarget();
  for (OPT_InstructionEnumeration e=in.reverseRealInstrEnumerator(); e.hasMoreElements(); ) {
    OPT_Instruction s=e.next();
    if (IfCmp2.conforms(s)) {
      if (IfCmp2.getTarget1(s).similar(outTarget))       IfCmp2.setTarget1(s,(OPT_BranchOperand)target.copy());
      if (IfCmp2.getTarget2(s).similar(outTarget))       IfCmp2.setTarget2(s,(OPT_BranchOperand)target.copy());
    }
 else     if (IfCmp.conforms(s)) {
      if (IfCmp.getTarget(s).similar(outTarget)) {
        IfCmp.setTarget(s,(OPT_BranchOperand)target.copy());
      }
    }
 else     if (InlineGuard.conforms(s)) {
      if (InlineGuard.getTarget(s).similar(outTarget))       InlineGuard.setTarget(s,(OPT_BranchOperand)target.copy());
    }
 else     if (Goto.conforms(s)) {
      foundGoto=true;
      if (Goto.getTarget(s).similar(outTarget))       Goto.setTarget(s,(OPT_BranchOperand)target.copy());
    }
 else     if (TableSwitch.conforms(s)) {
      foundGoto=true;
      if (TableSwitch.getDefault(s).similar(outTarget))       TableSwitch.setDefault(s,(OPT_BranchOperand)target.copy());
      for (int i=0; i < TableSwitch.getNumberOfTargets(s); i++)       if (TableSwitch.getTarget(s,i).similar(outTarget))       TableSwitch.setTarget(s,i,(OPT_BranchOperand)target.copy());
    }
 else     if (LowTableSwitch.conforms(s)) {
      foundGoto=true;
      for (int i=0; i < LowTableSwitch.getNumberOfTargets(s); i++)       if (LowTableSwitch.getTarget(s,i).similar(outTarget))       LowTableSwitch.setTarget(s,i,(OPT_BranchOperand)target.copy());
    }
 else     if (LookupSwitch.conforms(s)) {
      foundGoto=true;
      if (LookupSwitch.getDefault(s).similar(outTarget))       LookupSwitch.setDefault(s,(OPT_BranchOperand)target.copy());
      for (int i=0; i < LookupSwitch.getNumberOfTargets(s); i++)       if (LookupSwitch.getTarget(s,i).similar(outTarget))       LookupSwitch.setTarget(s,i,(OPT_BranchOperand)target.copy());
    }
 else {
      break;
    }
  }
  OPT_Instruction s=Goto.create(GOTO,out.makeJumpTarget());
  bb.appendInstruction(s);
  if (out != next) {
    if (!foundGoto) {
      s=Goto.create(GOTO,next.makeJumpTarget());
      in.appendInstruction(s);
    }
  }
  in.recomputeNormalOut(ir);
  bb.recomputeNormalOut(ir);
  return bb;
}

Fixed version (ground truth):
/** 
 * Make an empty basic block on an edge in the control flow graph, and fix up the control flow graph and IR instructions accordingly. This routine will create the control struture <pre> in -> bb -> out. </pre> <em> Precondition </em>: There is an edge in the control flow graph  from * in -> out.
 * @param in the source of the control flow edge
 * @param out the sink of the control flow edge
 * @param ir the governing IR
 * @return the new basic block bb
 */
public static OPT_BasicBlock makeBlockOnEdge(OPT_BasicBlock in,OPT_BasicBlock out,OPT_IR ir){
  OPT_BasicBlock bb=in.createSubBlock(out.firstInstruction().bcIndex,ir);
  OPT_BasicBlock next=in.nextBasicBlockInCodeOrder();
  if (next == null) {
    ir.cfg.addLastInCodeOrder(bb);
  }
 else {
    ir.cfg.breakCodeOrder(in,next);
    ir.cfg.linkInCodeOrder(in,bb);
    ir.cfg.linkInCodeOrder(bb,next);
  }
  boolean foundGoto=false;
  OPT_BranchOperand target=bb.makeJumpTarget();
  OPT_BranchOperand outTarget=out.makeJumpTarget();
  for (OPT_InstructionEnumeration e=in.reverseRealInstrEnumerator(); e.hasMoreElements(); ) {
    OPT_Instruction s=e.next();
    if (IfCmp2.conforms(s)) {
      if (IfCmp2.getTarget1(s).similar(outTarget))       IfCmp2.setTarget1(s,(OPT_BranchOperand)target.copy());
      if (IfCmp2.getTarget2(s).similar(outTarget))       IfCmp2.setTarget2(s,(OPT_BranchOperand)target.copy());
    }
 else     if (IfCmp.conforms(s)) {
      if (IfCmp.getTarget(s).similar(outTarget)) {
        IfCmp.setTarget(s,(OPT_BranchOperand)target.copy());
      }
    }
 else     if (InlineGuard.conforms(s)) {
      if (InlineGuard.getTarget(s).similar(outTarget))       InlineGuard.setTarget(s,(OPT_BranchOperand)target.copy());
    }
 else     if (Goto.conforms(s)) {
      foundGoto=true;
      if (Goto.getTarget(s).similar(outTarget))       Goto.setTarget(s,(OPT_BranchOperand)target.copy());
    }
 else     if (TableSwitch.conforms(s)) {
      foundGoto=true;
      if (TableSwitch.getDefault(s).similar(outTarget))       TableSwitch.setDefault(s,(OPT_BranchOperand)target.copy());
      for (int i=0; i < TableSwitch.getNumberOfTargets(s); i++)       if (TableSwitch.getTarget(s,i).similar(outTarget))       TableSwitch.setTarget(s,i,(OPT_BranchOperand)target.copy());
    }
 else     if (LowTableSwitch.conforms(s)) {
      foundGoto=true;
      for (int i=0; i < LowTableSwitch.getNumberOfTargets(s); i++)       if (LowTableSwitch.getTarget(s,i).similar(outTarget))       LowTableSwitch.setTarget(s,i,(OPT_BranchOperand)target.copy());
    }
 else     if (LookupSwitch.conforms(s)) {
      foundGoto=true;
      if (LookupSwitch.getDefault(s).similar(outTarget))       LookupSwitch.setDefault(s,(OPT_BranchOperand)target.copy());
      for (int i=0; i < LookupSwitch.getNumberOfTargets(s); i++)       if (LookupSwitch.getTarget(s,i).similar(outTarget))       LookupSwitch.setTarget(s,i,(OPT_BranchOperand)target.copy());
    }
 else {
      break;
    }
  }
  OPT_Instruction s=Goto.create(GOTO,out.makeJumpTarget());
  bb.appendInstruction(s);
  if (out != next) {
    if (!foundGoto) {
      OPT_BasicBlock jumpTarget=next;
      while (jumpTarget.isEmpty() && jumpTarget.isExceptionHandlerBasicBlock()) {
        jumpTarget=jumpTarget.nextBasicBlockInCodeOrder();
      }
      s=Goto.create(GOTO,jumpTarget.makeJumpTarget());
      in.appendInstruction(s);
    }
  }
  in.recomputeNormalOut(ir);
  bb.recomputeNormalOut(ir);
  return bb;
}