Program: 133107
Project: 133107
Buggy source:
/** 
 * @param logger
 * @param fn
 * @param block
 * @param cv
 * @param inst
 * @param insts if instructions inserted, leaves iterator pointing at previous instruction
 * @return
 */
private static boolean switchToImmediate(Logger logger,Function fn,ExecContext execCx,Block block,State cv,Instruction inst,ListIterator<Instruction> insts){
  MakeImmRequest req=inst.canMakeImmediate(cv.getClosed(),cv.getUnmapped(),false);
  if (req == null) {
    return false;
  }
  Block insertContext;
  ListIterator<Instruction> insertPoint;
  if (req.mode == TaskMode.LOCAL || req.mode == TaskMode.SYNC || (req.mode == TaskMode.LOCAL_CONTROL && execCx == ExecContext.CONTROL)) {
    insertContext=block;
    insertPoint=insts;
  }
 else {
    List<Var> used=Var.varListUnion(req.in,req.out);
    WaitStatement wait=new WaitStatement(fn.getName() + "String_Node_Str" + inst.shortOpName(),Collections.<Var>emptyList(),used,Collections.<Var>emptyList(),inst.getPriority(),WaitMode.TASK_DISPATCH,false,req.mode);
    insertContext=wait.getBlock();
    block.addContinuation(wait);
    insertPoint=insertContext.instructionIterator();
  }
  List<Instruction> alt=new ArrayList<Instruction>();
  List<Arg> inVals=new ArrayList<Arg>(req.in.size());
  HashMap<String,Arg> alreadyFetched=new HashMap<String,Arg>();
  for (  Var v : req.in) {
    Arg maybeVal;
    if (alreadyFetched.containsKey(v.name())) {
      maybeVal=alreadyFetched.get(v.name());
    }
 else {
      maybeVal=cv.findRetrieveResult(v);
    }
    if (maybeVal != null) {
      inVals.add(maybeVal);
      alreadyFetched.put(v.name(),maybeVal);
    }
 else {
      Var fetchedV=OptUtil.fetchValueOf(insertContext,alt,v);
      Arg fetched=Arg.createVar(fetchedV);
      inVals.add(fetched);
      alreadyFetched.put(v.name(),fetched);
    }
  }
  List<Var> outValVars=OptUtil.declareLocalOpOutputVars(insertContext,req.out);
  MakeImmChange change=inst.makeImmediate(outValVars,inVals);
  OptUtil.fixupImmChange(insertContext,change,alt,outValVars,req.out);
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + inst + "String_Node_Str"+ alt.toString());
  }
  insts.remove();
  for (  Instruction newInst : alt) {
    insertPoint.add(newInst);
  }
  if (inst == insertPoint) {
    ICUtil.rewindIterator(insts,alt.size());
  }
 else {
    insts.previous();
  }
  return true;
}

Fixed version (ground truth):
/** 
 * @param logger
 * @param fn
 * @param block
 * @param cv
 * @param inst
 * @param insts if instructions inserted, leaves iterator pointing at previous instruction
 * @return
 */
private static boolean switchToImmediate(Logger logger,Function fn,ExecContext execCx,Block block,State cv,Instruction inst,ListIterator<Instruction> insts){
  MakeImmRequest req=inst.canMakeImmediate(cv.getClosed(),cv.getUnmapped(),false);
  if (req == null) {
    return false;
  }
  Block insertContext;
  ListIterator<Instruction> insertPoint;
  if (req.mode == TaskMode.LOCAL || req.mode == TaskMode.SYNC || (req.mode == TaskMode.LOCAL_CONTROL && execCx == ExecContext.CONTROL)) {
    insertContext=block;
    insertPoint=insts;
  }
 else {
    List<Var> used=Var.varListUnion(req.in,req.out);
    WaitStatement wait=new WaitStatement(fn.getName() + "String_Node_Str" + inst.shortOpName(),Collections.<Var>emptyList(),used,Collections.<Var>emptyList(),inst.getPriority(),WaitMode.TASK_DISPATCH,false,req.mode);
    insertContext=wait.getBlock();
    block.addContinuation(wait);
    insertPoint=insertContext.instructionIterator();
  }
  List<Instruction> alt=new ArrayList<Instruction>();
  List<Arg> inVals=new ArrayList<Arg>(req.in.size());
  HashMap<String,Arg> alreadyFetched=new HashMap<String,Arg>();
  for (  Var v : req.in) {
    Arg maybeVal;
    if (alreadyFetched.containsKey(v.name())) {
      maybeVal=alreadyFetched.get(v.name());
    }
 else {
      maybeVal=cv.findRetrieveResult(v);
    }
    if (maybeVal != null) {
      inVals.add(maybeVal);
      alreadyFetched.put(v.name(),maybeVal);
    }
 else {
      Var fetchedV=OptUtil.fetchValueOf(insertContext,alt,v);
      Arg fetched=Arg.createVar(fetchedV);
      inVals.add(fetched);
      alreadyFetched.put(v.name(),fetched);
    }
  }
  List<Var> outValVars=OptUtil.declareLocalOpOutputVars(insertContext,req.out);
  MakeImmChange change=inst.makeImmediate(outValVars,inVals);
  OptUtil.fixupImmChange(block,insertContext,change,alt,outValVars,req.out);
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + inst + "String_Node_Str"+ alt.toString());
  }
  insts.remove();
  for (  Instruction newInst : alt) {
    insertPoint.add(newInst);
  }
  if (inst == insertPoint) {
    ICUtil.rewindIterator(insts,alt.size());
  }
 else {
    insts.previous();
  }
  return true;
}