nus-yam/ex-repair huggingface dataset:
Program: 132875
Project: 132875
Buggy source:
private CongruentSets(CongruenceType congType,CongruentSets parent,Set<Arg> contradictions){
  this.congType=congType;
  this.parent=parent;
  this.canonical=new HashMap<ArgOrCV,Arg>();
  this.canonicalInv=new MultiMap<Arg,ArgOrCV>();
  this.mergedInto=new MultiMap<Arg,Arg>();
  this.componentIndex=new MultiMap<Arg,ArgOrCV>();
  this.inaccessible=new HashSet<Var>();
  this.contradictions=contradictions;
  this.mergeQueue=new LinkedList<ToMerge>();
  this.recanonicalizeQueue=new LinkedList<Arg>();
  if (parent != null) {
    this.constShareEnabled=parent.constShareEnabled;
    this.constFoldEnabled=parent.constFoldEnabled;
  }
 else {
    try {
      this.constShareEnabled=Settings.getBoolean(Settings.OPT_SHARED_CONSTANTS);
      this.constFoldEnabled=Settings.getBoolean(Settings.OPT_CONSTANT_FOLD);
    }
 catch (    InvalidOptionException e) {
      e.printStackTrace();
      throw new STCRuntimeError(e.getMessage());
    }
  }
}

Fixed version (ground truth):
private CongruentSets(CongruenceType congType,CongruentSets parent,Set<Arg> contradictions){
  this.congType=congType;
  this.parent=parent;
  this.canonical=new HashMap<ArgOrCV,Arg>();
  this.canonicalInv=new MultiMap<Arg,ArgOrCV>();
  this.mergedInto=new MultiMap<Arg,Arg>();
  this.componentIndex=new MultiMap<Arg,ArgCV>();
  this.inaccessible=new HashSet<Var>();
  this.contradictions=contradictions;
  this.mergeQueue=new LinkedList<ToMerge>();
  this.recanonicalizeQueue=new LinkedList<Arg>();
  if (parent != null) {
    this.constShareEnabled=parent.constShareEnabled;
    this.constFoldEnabled=parent.constFoldEnabled;
  }
 else {
    try {
      this.constShareEnabled=Settings.getBoolean(Settings.OPT_SHARED_CONSTANTS);
      this.constFoldEnabled=Settings.getBoolean(Settings.OPT_CONSTANT_FOLD);
    }
 catch (    InvalidOptionException e) {
      e.printStackTrace();
      throw new STCRuntimeError(e.getMessage());
    }
  }
}
Program: 132876
Project: 132876
Buggy source:
private ArgOrCV canonicalize(GlobalConstants consts,ArgOrCV result){
  if (result.isCV()) {
    ComputedValue<Arg> resultValue=result.cv();
    if (resultValue.isCopy() || resultValue.isAlias()) {
      result=new ArgOrCV(resultValue.getInput(0));
    }
 else     if (resultValue.isDerefCompVal()) {
      ArgOrCV resolvedRef=tryResolveRef(resultValue);
      if (resolvedRef != null) {
        result=resolvedRef;
      }
    }
 else     if (constFoldEnabled && this.congType == CongruenceType.VALUE) {
      ArgOrCV constantFolded=tryConstantFold(resultValue);
      if (constantFolded != null) {
        result=constantFolded;
      }
    }
  }
  if (constShareEnabled && result.isCV()) {
    result=tryReplaceGlobalConstant(consts,result);
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Do any canonicalization of result value here, e.g. to implement constant folding, etc.
 * @param consts 
 * @param resVal
 * @return
 */
public ArgOrCV canonicalize(GlobalConstants consts,ArgCV origVal){
  return canonicalizeInternal(consts,canonicalizeInputs(origVal));
}
Program: 132877
Project: 132877
Buggy source:
/** 
 * Convert ComputedValue parameterized with <Arg> to ComputedValue parameterized with ComputedValue
 * @param cv
 * @return
 */
private ArgOrCV canonicalizeInputs(ArgCV cv){
  List<Arg> inputs=cv.getInputs();
  List<Arg> newInputs=new ArrayList<Arg>(inputs.size());
  for (  Arg input : inputs) {
    if (cv.canSubstituteInputs(congType)) {
      Arg canonicalInput=findCanonical(new ArgOrCV(input));
      assert(canonicalInput != null);
      newInputs.add(canonicalInput);
    }
 else {
      newInputs.add(input);
    }
  }
  ArgOrCV newCV=new ArgOrCV(cv.op,cv.subop,newInputs);
  if (findCanonical(newCV) == null) {
    for (    Arg newInput : newInputs) {
      addInputIndex(newInput,newCV);
    }
  }
  return newCV;
}

Fixed version (ground truth):
/** 
 * Convert ComputedValue parameterized with <Arg> to ComputedValue parameterized with ComputedValue
 * @param cv
 * @return
 */
private ArgCV canonicalizeInputs(ArgCV cv){
  List<Arg> inputs=cv.getInputs();
  List<Arg> newInputs=new ArrayList<Arg>(inputs.size());
  for (  Arg input : inputs) {
    if (cv.canSubstituteInputs(congType)) {
      Arg canonicalInput=findCanonical(input);
      assert(canonicalInput != null);
      newInputs.add(canonicalInput);
    }
 else {
      newInputs.add(input);
    }
  }
  ArgCV newCV=new ArgCV(cv.op,cv.subop,newInputs);
  if (findCanonicalInternal(newCV) == null) {
    for (    Arg newInput : newInputs) {
      addInputIndex(newInput,newCV);
    }
  }
  return newCV;
}
Program: 132878
Project: 132878
Buggy source:
public void markContradiction(Arg arg){
  assert(arg != null);
  arg=findCanonical(arg);
  boolean newContradiction=contradictions.add(arg);
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + arg + "String_Node_Str"+ newContradiction);
  }
  if (!newContradiction) {
    return;
  }
  CongruentSets curr=this;
  do {
    for (    ArgOrCV setMember : curr.canonicalInv.get(arg)) {
      if (setMember.isArg() && !setMember.arg().equals(arg)) {
        if (logger.isTraceEnabled()) {
          logger.trace("String_Node_Str" + arg + "String_Node_Str"+ setMember);
        }
        markContradiction(setMember.arg());
      }
 else       if (setMember.isCV()) {
        addCVContradictions(setMember.cv());
      }
    }
    curr=curr.parent;
  }
 while (curr != null);
  curr=this;
  do {
    for (    ArgOrCV cv : curr.componentIndex.get(arg)) {
      if (logger.isTraceEnabled()) {
        logger.trace("String_Node_Str" + arg + "String_Node_Str"+ cv);
      }
      Arg set=findCanonical(cv);
      if (set != null) {
        markContradiction(set);
      }
    }
    curr=curr.parent;
  }
 while (curr != null);
}

Fixed version (ground truth):
public void markContradiction(Arg arg){
  assert(arg != null);
  arg=findCanonical(arg);
  boolean newContradiction=contradictions.add(arg);
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + arg + "String_Node_Str"+ newContradiction);
  }
  if (!newContradiction) {
    return;
  }
  CongruentSets curr=this;
  do {
    for (    ArgOrCV setMember : curr.canonicalInv.get(arg)) {
      if (setMember.isArg() && !setMember.arg().equals(arg)) {
        if (logger.isTraceEnabled()) {
          logger.trace("String_Node_Str" + arg + "String_Node_Str"+ setMember);
        }
        markContradiction(setMember.arg());
      }
 else       if (setMember.isCV()) {
        addCVContradictions(setMember.cv());
      }
    }
    curr=curr.parent;
  }
 while (curr != null);
  curr=this;
  do {
    for (    ArgCV cv : curr.componentIndex.get(arg)) {
      if (logger.isTraceEnabled()) {
        logger.trace("String_Node_Str" + arg + "String_Node_Str"+ cv);
      }
      Arg set=findCanonical(new ArgOrCV(cv));
      if (set != null) {
        markContradiction(set);
      }
    }
    curr=curr.parent;
  }
 while (curr != null);
}
Program: 132879
Project: 132879
Buggy source:
/** 
 * Try to resolve a reference lookup to the original thing dereferenced
 * @param val
 * @return
 */
private ArgOrCV tryResolveRef(ComputedValue<Arg> val){
  assert(val.isDerefCompVal());
  Arg ref=val.getInput(0);
  for (  ArgOrCV v : findCongruentValues(ref)) {
    if (v.isCV()) {
      ArgCV v2=v.cv();
      if (v2.isArrayMemberRef()) {
        return new ArgOrCV(ComputedValue.derefArrayMemberRef(v2));
      }
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Try to resolve a reference lookup to the original thing dereferenced
 * @param val
 * @return
 */
private ArgCV tryResolveRef(ComputedValue<Arg> val){
  assert(val.isDerefCompVal());
  Arg ref=val.getInput(0);
  for (  ArgOrCV v : findCongruentValues(ref)) {
    if (v.isCV()) {
      ArgCV v2=v.cv();
      if (v2.isArrayMemberRef()) {
        return ComputedValue.derefArrayMemberRef(v2);
      }
    }
  }
  return null;
}
Program: 132880
Project: 132880
Buggy source:
/** 
 * Try to constant-fold the expression
 * @param val
 * @return
 */
private ArgOrCV tryConstantFold(ComputedValue<Arg> val){
  assert(constFoldEnabled);
  assert(this.congType == CongruenceType.VALUE);
  return ConstantFolder.constantFold(logger,this,val);
}

Fixed version (ground truth):
/** 
 * Try to constant-fold the expression
 * @param val
 * @return
 */
private ArgOrCV tryConstantFold(ArgCV val){
  assert(constFoldEnabled);
  assert(this.congType == CongruenceType.VALUE);
  return ConstantFolder.constantFold(logger,this,val);
}
Program: 132881
Project: 132881
Buggy source:
/** 
 * Keep index of where Arg appears.  When merge happens, need to go through and replace old Arg with new canonical Arg.  We also use this to propagate contradiction info among different sets.  We need to track constants as these are often the canonical member of a set.
 */
private void addInputIndex(Arg newInput,ArgOrCV newCV){
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + newInput + "String_Node_Str"+ newCV);
  }
  componentIndex.put(newInput,newCV);
}

Fixed version (ground truth):
/** 
 * Keep index of where Arg appears.  When merge happens, need to go through and replace old Arg with new canonical Arg.  We also use this to propagate contradiction info among different sets.  We need to track constants as these are often the canonical member of a set.
 */
private void addInputIndex(Arg newInput,ArgCV newCV){
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + newInput + "String_Node_Str"+ newCV);
  }
  componentIndex.put(newInput,newCV);
}
Program: 132882
Project: 132882
Buggy source:
/** 
 * See if the result of a value retrieval is already in scope
 * @param v
 * @return
 */
public Arg findRetrieveResult(Var v){
  ArgCV cvRetrieve=ComputedValue.retrieveCompVal(v);
  if (cvRetrieve == null) {
    return null;
  }
  return byValue.findCanonical(cvRetrieve);
}

Fixed version (ground truth):
/** 
 * See if the result of a value retrieval is already in scope
 * @param v
 * @return
 */
public Arg findRetrieveResult(Var v){
  ArgCV cvRetrieve=ComputedValue.retrieveCompVal(v);
  if (cvRetrieve == null) {
    return null;
  }
  Arg val=byValue.findCanonical(cvRetrieve);
  if (val != null && !byValue.contradictions.contains(val)) {
    return val;
  }
 else {
    return null;
  }
}
Program: 132883
Project: 132883
Buggy source:
public void markContradiction(Arg arg){
  arg=findCanonical(arg);
  boolean newContradiction=contradictions.add(arg);
  if (!newContradiction) {
    return;
  }
  CongruentSet curr=this;
  do {
    for (    RecCV setMember : curr.canonicalInv.get(arg)) {
      if (setMember.isArg() && !setMember.arg().equals(arg)) {
        if (logger.isTraceEnabled()) {
          logger.trace("String_Node_Str" + arg + "String_Node_Str"+ setMember);
        }
        contradictions.add(setMember.arg());
      }
    }
    curr=curr.parent;
  }
 while (curr != null);
  curr=this;
  do {
    for (    RecCV cv : curr.componentIndex.get(arg)) {
      if (logger.isTraceEnabled()) {
        logger.trace("String_Node_Str" + arg + "String_Node_Str"+ cv);
      }
      markContradiction(findCanonical(cv));
    }
    curr=curr.parent;
  }
 while (curr != null);
}

Fixed version (ground truth):
public void markContradiction(Arg arg){
  arg=findCanonical(arg);
  boolean newContradiction=contradictions.add(arg);
  if (!newContradiction) {
    return;
  }
  CongruentSet curr=this;
  do {
    for (    RecCV setMember : curr.canonicalInv.get(arg)) {
      if (setMember.isArg() && !setMember.arg().equals(arg)) {
        if (logger.isTraceEnabled()) {
          logger.trace("String_Node_Str" + arg + "String_Node_Str"+ setMember);
        }
        contradictions.add(setMember.arg());
      }
    }
    curr=curr.parent;
  }
 while (curr != null);
  curr=this;
  do {
    for (    RecCV cv : curr.componentIndex.get(arg)) {
      if (logger.isTraceEnabled()) {
        logger.trace("String_Node_Str" + arg + "String_Node_Str"+ cv);
      }
      Arg set=findCanonical(cv);
      if (set != null) {
        markContradiction(set);
      }
    }
    curr=curr.parent;
  }
 while (curr != null);
}
Program: 132884
Project: 132884
Buggy source:
public boolean isAvailable(RecCV val,CongruenceType congType){
  return findCanonical(val,congType) != null;
}

Fixed version (ground truth):
public boolean isAvailable(ArgCV val,CongruenceType congType){
  return findCanonical(val,congType) != null;
}
Program: 132885
Project: 132885
Buggy source:
/** 
 * Update a congruentSet with the information that value is stored in location
 * @param errContext
 * @param location
 * @param value
 * @param congruent
 * @param addInverses
 * @return
 */
public boolean update(String errContext,Arg location,ArgCV value,CongruentSet congruent,boolean addInverses){
  Arg canonLoc=congruent.findCanonical(new RecCV(location));
  RecCV canonVal=canonicalize(congruent,value);
  updateCanonical(errContext,canonLoc,canonVal,congruent);
  if (addInverses) {
    addInverses(errContext,canonLoc,canonVal);
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Update a congruentSet with the information that value is stored in location
 * @param errContext
 * @param location
 * @param value
 * @param congruent
 * @param addInverses
 * @return
 */
public boolean update(String errContext,Arg location,ArgCV value,CongruentSet congruent,boolean addInverses){
  Arg canonLoc=congruent.findCanonical(new RecCV(location));
  RecCV canonVal=canonicalize(congruent,value);
  Arg canonLocFromVal=congruent.findCanonical(canonVal);
  if (canonLocFromVal == null) {
    congruent.addToSet(canonVal,canonLoc);
  }
 else {
    mergeSets(errContext,canonVal,congruent,canonLoc,canonLocFromVal);
  }
  if (addInverses) {
    addInverses(errContext,canonLoc,canonVal);
  }
  return true;
}
Program: 132886
Project: 132886
Buggy source:
private void addInverses(String errContext,Arg canonLoc,RecCV canonVal){
  if (canonVal.isCV() && canonVal.cv().inputs.size() == 1) {
    ComputedValue<RecCV> cv=canonVal.cv();
    RecCV input=cv.getInput(0);
    if (input.isArg()) {
      Arg invOutput=input.arg();
      CongruentSet valueSet=getCongruentSet(CongruenceType.VALUE);
      if (cv.op().isAssign()) {
        ArgCV invVal=ComputedValue.retrieveCompVal(canonLoc.getVar());
        update(errContext,invOutput,invVal,valueSet,false);
      }
 else       if (cv.op().isRetrieve()) {
        ArgCV invVal=new ArgCV(Opcode.assignOpcode(invOutput.getVar()),canonLoc.asList());
        update(errContext,invOutput,invVal,valueSet,false);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Add any inverse operations that can be directly inferred from a value that was just added
 * @param errContext
 * @param canonLoc
 * @param canonVal
 */
private void addInverses(String errContext,Arg canonLoc,RecCV canonVal){
  if (canonVal.isCV() && canonVal.cv().inputs.size() == 1) {
    ComputedValue<RecCV> cv=canonVal.cv();
    RecCV input=cv.getInput(0);
    if (input.isArg()) {
      Arg invOutput=input.arg();
      CongruentSet valueSet=getCongruentSet(CongruenceType.VALUE);
      if (cv.op().isAssign()) {
        ArgCV invVal=ComputedValue.retrieveCompVal(canonLoc.getVar());
        update(errContext,invOutput,invVal,valueSet,false);
      }
 else       if (cv.op().isRetrieve()) {
        ArgCV invVal=new ArgCV(Opcode.assignOpcode(invOutput.getVar()),canonLoc.asList());
        update(errContext,invOutput,invVal,valueSet,false);
      }
    }
  }
}
Program: 132887
Project: 132887
Buggy source:
@Override public boolean equals(Object obj){
  if (this == obj)   return true;
  if (obj == null)   return false;
  if (getClass() != obj.getClass())   return false;
  RecCV other=(RecCV)obj;
  if (arg == null) {
    if (other.arg != null)     return false;
  }
 else   if (!arg.equals(other.arg))   return false;
  if (cv == null) {
    if (other.cv != null)     return false;
  }
 else   if (!cv.equals(other.cv))   return false;
  return true;
}

Fixed version (ground truth):
@Override public boolean equals(Object obj){
  if (this == obj)   return true;
  if (obj == null)   return false;
  if (!(obj instanceof RecCV))   throw new STCRuntimeError("String_Node_Str" + this.getClass().getName() + "String_Node_Str"+ obj.getClass().getName());
  RecCV other=(RecCV)obj;
  if (arg == null) {
    if (other.arg != null)     return false;
  }
 else   if (!arg.equals(other.arg))   return false;
  if (cv == null) {
    if (other.cv != null)     return false;
  }
 else   if (!cv.equals(other.cv))   return false;
  return true;
}
Program: 132888
Project: 132888
Buggy source:
@Override public Arg get(Object key){
  assert(key instanceof Var);
  Var v=(Var)key;
  Arg replace=null;
  CongruentSet curr=CongruentSet.this;
  List<CongruentSet> visited=new ArrayList<CongruentSet>();
  do {
    replace=curr.canonical.get(v.asArg());
    if (replace != null) {
      break;
    }
    visited.add(curr);
    curr=curr.parent;
  }
 while (curr != null);
  if (replace != null && replace.isVar()) {
    for (    CongruentSet s : visited) {
      if (s.inaccessible.contains(replace.getVar())) {
        return null;
      }
    }
  }
  if (replace != null && contradictions.contains(replace)) {
    return null;
  }
  return replace;
}

Fixed version (ground truth):
@Override public Arg get(Object key){
  assert(key instanceof Var);
  Var v=(Var)key;
  RecCV cv=new RecCV(v.asArg());
  Arg replace=null;
  CongruentSet curr=CongruentSet.this;
  List<CongruentSet> visited=new ArrayList<CongruentSet>();
  do {
    replace=curr.canonical.get(cv);
    if (replace != null) {
      break;
    }
    visited.add(curr);
    curr=curr.parent;
  }
 while (curr != null);
  if (replace != null && replace.isVar()) {
    for (    CongruentSet s : visited) {
      if (s.inaccessible.contains(replace.getVar())) {
        if (logger.isTraceEnabled()) {
          logger.trace(v + "String_Node_Str" + replace+ "String_Node_Str"+ congType+ "String_Node_Str"+ "String_Node_Str");
        }
        return null;
      }
    }
  }
  if (replace != null && contradictions.contains(replace)) {
    if (logger.isTraceEnabled()) {
      logger.trace(v + "String_Node_Str" + replace+ "String_Node_Str"+ congType+ "String_Node_Str"+ "String_Node_Str");
    }
    return null;
  }
  if (logger.isTraceEnabled()) {
    logger.trace(v + "String_Node_Str" + replace+ "String_Node_Str"+ congType+ "String_Node_Str");
  }
  return replace;
}
Program: 132889
Project: 132889
Buggy source:
/** 
 * Find computed values that appear in all branches but not parent
 * @param parentState
 * @param congType 
 * @param branchStates
 * @param alreadyAdded ignore these
 * @return
 */
private static List<ArgCV> findAllBranchCVs(CongruentVars parentState,CongruenceType congType,List<CongruentVars> branchStates,List<ArgCV> alreadyAdded){
  List<ArgCV> allBranchCVs=new ArrayList<ArgCV>();
  CongruentVars firstState=branchStates.get(0);
  for (  RecCV val : firstState.availableThisScope(congType)) {
    ArgCV convertedVal=parentState.convertToArgs(val,congType);
    if (convertedVal != null) {
      if (!alreadyAdded.contains(val) && !parentState.isAvailable(val,congType)) {
        int nBranches=branchStates.size();
        boolean presentInAll=true;
        for (        CongruentVars otherState : branchStates.subList(1,nBranches)) {
          if (!otherState.isAvailable(val,congType)) {
            presentInAll=false;
            break;
          }
        }
        if (presentInAll) {
          allBranchCVs.add(convertedVal);
        }
      }
    }
  }
  return allBranchCVs;
}

Fixed version (ground truth):
/** 
 * Find computed values that appear in all branches but not parent
 * @param parentState
 * @param congType 
 * @param branchStates
 * @param alreadyAdded ignore these
 * @return
 */
private static List<ArgCV> findAllBranchCVs(CongruentVars parentState,CongruenceType congType,List<CongruentVars> branchStates,List<ArgCV> alreadyAdded){
  List<ArgCV> allBranchCVs=new ArrayList<ArgCV>();
  CongruentVars firstState=branchStates.get(0);
  for (  RecCV val : firstState.availableThisScope(congType)) {
    ArgCV convertedVal=parentState.convertToArgs(val,congType);
    if (convertedVal != null) {
      if (!alreadyAdded.contains(convertedVal) && !parentState.isAvailable(convertedVal,congType)) {
        int nBranches=branchStates.size();
        boolean presentInAll=true;
        for (        CongruentVars otherState : branchStates.subList(1,nBranches)) {
          if (!otherState.isAvailable(convertedVal,congType)) {
            presentInAll=false;
            break;
          }
        }
        if (presentInAll) {
          allBranchCVs.add(convertedVal);
        }
      }
    }
  }
  return allBranchCVs;
}
Program: 132890
Project: 132890
Buggy source:
/** 
 * ValLoc representing result of dereference ref
 * @param contents of ref
 * @param ref
 * @param copied if it is a copy of the original
 */
public static ValLoc derefCompVal(Var v,Var ref,IsValCopy copied){
  assert(Types.isRefTo(ref,v));
  return new ValLoc(ComputedValue.derefCompVal(ref),v.asArg(),Closed.MAYBE_NOT,copied);
}

Fixed version (ground truth):
/** 
 * ValLoc representing result of dereference ref
 * @param contents of ref
 * @param ref
 * @param copied if it is a copy of the original
 */
public static ValLoc derefCompVal(Var v,Var ref,IsValCopy copied){
}
Program: 132892
Project: 132892
Buggy source:
@Override public boolean equals(Object obj){
  if (this == obj)   return true;
  if (obj == null)   return false;
  if (!(obj instanceof RecCV))   throw new STCRuntimeError("String_Node_Str" + this.getClass().getName() + "String_Node_Str"+ obj.getClass().getName());
  RecCV other=(RecCV)obj;
  if (arg == null) {
    if (other.arg != null)     return false;
  }
 else   if (!arg.equals(other.arg))   return false;
  if (cv == null) {
    if (other.cv != null)     return false;
  }
 else   if (!cv.equals(other.cv))   return false;
  return true;
}

Fixed version (ground truth):
@Override public boolean equals(Object obj){
  if (this == obj)   return true;
  if (obj == null)   return false;
  if (!(obj instanceof RecCV))   throw new STCRuntimeError("String_Node_Str" + this.getClass().getName() + "String_Node_Str"+ obj.getClass().getName());
  RecCV other=(RecCV)obj;
  if (arg != null) {
    if (other.arg == null) {
      return false;
    }
    return arg.equals(other.arg);
  }
 else {
    assert(cv != null);
    if (other.cv == null) {
      return false;
    }
    return cv.equals(other.cv);
  }
}
Program: 132893
Project: 132893
Buggy source:
/** 
 * Recanonicalize components.  If an old computed value had a reference to oldCanonical in it, then it's no longer canonical, so need to replace. This will add to the merge queue, so callers need to process it before returning to other modules
 * @param oldComponent
 * @param newComponent if null, just recanonicalize
 */
private void updateCanonicalComponents(GlobalConstants consts,Arg oldComponent,Arg newComponent){
  CongruentSets curr=this;
  do {
    for (    RecCV outerCV : curr.componentIndex.get(oldComponent)) {
      assert(outerCV.isCV());
      RecCV newOuterCV=outerCV;
      if (newComponent != null) {
        List<RecCV> newInputs=replaceInput(outerCV.cv().getInputs(),oldComponent,newComponent);
        newOuterCV=new RecCV(outerCV.cv().substituteInputs(newInputs));
      }
      newOuterCV=canonicalize(consts,newOuterCV);
      if (newOuterCV != outerCV) {
        if (logger.isTraceEnabled()) {
          logger.trace("String_Node_Str" + oldComponent + "String_Node_Str"+ newComponent+ "String_Node_Str"+ outerCV);
        }
        this.componentIndex.put(newComponent,newOuterCV);
        Arg canonical=findCanonical(outerCV);
        if (canonical != null) {
          Arg newCanonical=findCanonical(newOuterCV);
          if (newCanonical != null && !newCanonical.equals(canonical)) {
            mergeQueue.add(new ToMerge(canonical,newCanonical));
            if (logger.isTraceEnabled()) {
              if (newComponent != null) {
                logger.trace("String_Node_Str" + oldComponent + "String_Node_Str"+ newComponent+ "String_Node_Str"+ canonical+ "String_Node_Str"+ newCanonical);
              }
 else {
                logger.trace("String_Node_Str" + oldComponent + "String_Node_Str"+ canonical+ "String_Node_Str"+ newCanonical);
              }
            }
          }
 else {
            addToSet(consts,newOuterCV,canonical);
          }
          if (contradictions.contains(newComponent) && !contradictions.contains(oldComponent)) {
            markContradiction(canonical);
          }
        }
      }
    }
    curr=curr.parent;
  }
 while (curr != null);
  this.componentIndex.remove(oldComponent);
}

Fixed version (ground truth):
/** 
 * Recanonicalize components.  If an old computed value had a reference to oldCanonical in it, then it's no longer canonical, so need to replace. This will add to the merge queue, so callers need to process it before returning to other modules
 * @param oldComponent
 * @param newComponent if null, just recanonicalize
 */
private void updateCanonicalComponents(GlobalConstants consts,Arg oldComponent,Arg newComponent){
}
Program: 132894
Project: 132894
Buggy source:
/** 
 * Keep index of where Arg appears.  When merge happens, need to go through and replace old Arg with new canonical Arg.
 */
private void addInputIndex(Arg newInput,RecCV newCV){
  componentIndex.put(newInput,newCV);
}

Fixed version (ground truth):
/** 
 * Keep index of where Arg appears.  When merge happens, need to go through and replace old Arg with new canonical Arg.
 */
private void addInputIndex(Arg newInput,RecCV newCV){
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + newInput + "String_Node_Str"+ newCV);
  }
  componentIndex.put(newInput,newCV);
}
Program: 132895
Project: 132895
Buggy source:
private void processQueues(GlobalConstants consts){
  Arg oldCanon;
  Arg newCanon;
  do {
    while (!mergeQueue.isEmpty()) {
      ToMerge merge=mergeQueue.removeFirst();
      oldCanon=findCanonical(merge.oldSet);
      newCanon=findCanonical(merge.newSet);
      if (!oldCanon.equals(newCanon)) {
        changeCanonicalOnce(consts,oldCanon,newCanon);
      }
    }
    while (!futureValQueue.isEmpty()) {
      Var futureWithVal=futureValQueue.removeFirst();
      updateCanonicalComponents(consts,futureWithVal.asArg(),null);
    }
  }
 while (!mergeQueue.isEmpty() || !futureValQueue.isEmpty());
}

Fixed version (ground truth):
private void processQueues(GlobalConstants consts){
  if (logger.isTraceEnabled() && !mergeQueue.isEmpty() && !futureValQueue.isEmpty()) {
    logger.trace("String_Node_Str");
    logger.trace("String_Node_Str" + mergeQueue);
    logger.trace("String_Node_Str" + futureValQueue);
  }
  Arg oldCanon;
  Arg newCanon;
  do {
    while (!mergeQueue.isEmpty()) {
      ToMerge merge=mergeQueue.removeFirst();
      oldCanon=findCanonical(merge.oldSet);
      newCanon=findCanonical(merge.newSet);
      if (!oldCanon.equals(newCanon)) {
        changeCanonicalOnce(consts,oldCanon,newCanon);
      }
    }
    while (!futureValQueue.isEmpty()) {
      Var futureWithVal=futureValQueue.removeFirst();
      updateCanonicalComponents(consts,futureWithVal.asArg(),null);
    }
  }
 while (!mergeQueue.isEmpty() || !futureValQueue.isEmpty());
}
Program: 132896
Project: 132896
Buggy source:
/** 
 * Try to do compile-time evaluation of operator
 * @param op
 * @param inputs inputs to operator.  Null or a variable if not constant
 * @return output value of op if it could be evaluated at compile-time, nullotherwise.  Also returns null if the operator is simply a copy, since no reduction can occur then 
 */
public static Arg eval(BuiltinOpcode op,List<Arg> inputs){
  if (Operators.isShortCircuitable(op)) {
    return evalShortCircuit(op,inputs);
  }
 else   if (Operators.isCopy(op)) {
    return null;
  }
 else {
    boolean allInt=true;
    boolean allFloat=true;
    boolean allString=true;
    boolean allBool=true;
    for (    Arg in : inputs) {
      if (in == null) {
        return null;
      }
      allInt=allInt && in.isIntVal();
      allFloat=allFloat && in.isFloatVal();
      allString=allString && in.isStringVal();
      allBool=allBool && in.isBoolVal();
    }
    if (allInt) {
      return evalIntOp(op,inputs);
    }
 else     if (allFloat) {
      return evalFloatOp(op,inputs);
    }
 else     if (allString) {
      return evalStringOp(op,inputs);
    }
 else     if (allBool) {
      return evalBoolOp(op,inputs);
    }
 else {
      return evalOtherOp(op,inputs);
    }
  }
}

Fixed version (ground truth):
/** 
 * Try to do compile-time evaluation of operator
 * @param op
 * @param inputs inputs to operator.  Null or a variable if not constant
 * @return output value of op if it could be evaluated at compile-time, nullotherwise.  Also returns null if the operator is simply a copy, since no reduction can occur then 
 */
public static Arg eval(BuiltinOpcode op,List<Arg> inputs){
  if (Operators.isShortCircuitable(op)) {
    return evalShortCircuit(op,inputs);
  }
 else   if (Operators.isCopy(op)) {
    return null;
  }
 else {
    boolean allInt=true;
    boolean allFloat=true;
    boolean allString=true;
    boolean allBool=true;
    boolean allConst=true;
    for (    Arg in : inputs) {
      if (in == null) {
        return null;
      }
      allInt=allInt && in.isImmediateInt();
      allFloat=allFloat && in.isImmediateFloat();
      allString=allString && in.isImmediateString();
      allBool=allBool && in.isImmediateBool();
      allConst=allConst && in.isConstant();
    }
    if (allConst) {
      if (allInt) {
        return evalIntOp(op,inputs);
      }
 else       if (allFloat) {
        return evalFloatOp(op,inputs);
      }
 else       if (allString) {
        return evalStringOp(op,inputs);
      }
 else       if (allBool) {
        return evalBoolOp(op,inputs);
      }
 else {
        return evalOtherOp(op,inputs);
      }
    }
    return null;
  }
}
Program: 132897
Project: 132897
Buggy source:
/** 
 * Constant folding for short-circuitable operations where we don't always need to know both arguments to evaluate
 * @param constArgs unknown args are null
 * @return
 */
private static Arg evalShortCircuit(BuiltinOpcode op,List<Arg> constArgs){
  List<Arg> constInputs=new ArrayList<Arg>(2);
  for (  Arg in : constArgs) {
    if (in != null) {
      assert(in.isBoolVal());
      constInputs.add(in);
    }
  }
  if (constInputs.size() >= 1) {
    boolean arg1=constInputs.get(0).getBoolLit();
    if (constInputs.size() == 2) {
      boolean arg2=constInputs.get(1).getBoolLit();
switch (op) {
case OR:
        return Arg.createBoolLit(arg1 || arg2);
case AND:
      return Arg.createBoolLit(arg1 && arg2);
default :
  }
}
 else if (constInputs.size() == 1) {
  if (op == BuiltinOpcode.AND && arg1) {
    return Arg.createBoolLit(true);
  }
 else   if (op == BuiltinOpcode.OR && !arg1) {
    return Arg.createBoolLit(false);
  }
}
}
return null;
}

Fixed version (ground truth):
/** 
 * Constant folding for short-circuitable operations where we don't always need to know both arguments to evaluate
 * @param constArgs unknown args are null.  Currently assume 2 args
 * @return
 */
private static Arg evalShortCircuit(BuiltinOpcode op,List<Arg> constArgs){
}
Program: 132898
Project: 132898
Buggy source:
private RecCV tryConstantFold(CongruentSet congruent,ComputedValue<RecCV> val){
  if (val.op == Opcode.ASYNC_OP || val.op == Opcode.LOCAL_OP) {
    List<Arg> inputs;
    if (val.op == Opcode.LOCAL_OP) {
      inputs=convertToArgs(val);
    }
 else {
      assert(val.op == Opcode.ASYNC_OP);
      inputs=findFutureValues(val,congruent);
    }
    if (logger.isTraceEnabled()) {
      logger.trace("String_Node_Str" + val + "String_Node_Str"+ inputs);
    }
    if (inputs != null) {
      Arg res=OpEvaluator.eval((BuiltinOpcode)val.subop,inputs);
      if (res != null) {
        if (logger.isDebugEnabled()) {
          logger.debug("String_Node_Str" + val + "String_Node_Str"+ res);
        }
        boolean futureResult=val.op != Opcode.LOCAL_OP;
        return canonicalConstantVal(futureResult,res);
      }
    }
  }
 else   if (val.op == Opcode.IS_MAPPED) {
  }
  return null;
}

Fixed version (ground truth):
private RecCV tryConstantFold(CongruentSet congruent,ComputedValue<RecCV> val){
  if (val.op == Opcode.ASYNC_OP || val.op == Opcode.LOCAL_OP) {
    List<Arg> inputs;
    if (val.op == Opcode.LOCAL_OP) {
      inputs=convertToArgs(val);
    }
 else {
      assert(val.op == Opcode.ASYNC_OP);
      inputs=findFutureValues(val,congruent);
    }
    if (logger.isTraceEnabled()) {
      logger.trace("String_Node_Str" + val + "String_Node_Str"+ inputs);
    }
    if (inputs != null) {
      Arg res=OpEvaluator.eval((BuiltinOpcode)val.subop,inputs);
      if (res != null) {
        if (logger.isDebugEnabled()) {
          logger.debug("String_Node_Str" + val + "String_Node_Str"+ res);
        }
        boolean futureResult=val.op != Opcode.LOCAL_OP;
        return valFromArg(futureResult,res);
      }
    }
  }
 else   if (val.op == Opcode.IS_MAPPED) {
  }
  return null;
}
Program: 132899
Project: 132899
Buggy source:
public static Map<Var,Arg> constantFold(BuiltinOpcode op,Var outVar,List<Arg> inputs){
  Arg out=OpEvaluator.eval(op,inputs);
  return (out == null) ? null : Collections.singletonMap(outVar,out);
}

Fixed version (ground truth):
public static Map<Var,Arg> constantFold(BuiltinOpcode op,Var outVar,List<Arg> inputs){
  Arg out=OpEvaluator.eval(op,inputs);
  if (out != null && out.isConstant()) {
    return Collections.singletonMap(outVar,out);
  }
 else {
    return null;
  }
}
Program: 132900
Project: 132900
Buggy source:
private UnifiedValues findCongruencesContRec(Program prog,Function fn,ExecContext execCx,Continuation cont,int stmtIndex,Congruences state,Map<Block,Congruences> result){
  logger.trace("String_Node_Str" + cont.getType());
  Congruences contState=state.enterContinuation(cont.inheritsParentVars(),stmtIndex);
  List<BlockingVar> contClosedVars=cont.blockingVars(true);
  if (contClosedVars != null) {
    for (    BlockingVar bv : contClosedVars) {
      contState.markClosed(bv.var,stmtIndex,bv.recursive);
    }
  }
  boolean unifyBranches=cont.isExhaustiveSyncConditional();
  List<Congruences> branchStates=unifyBranches ? new ArrayList<Congruences>() : null;
  for (  Block contBlock : cont.getBlocks()) {
    Congruences blockState=contState.enterBlock();
    findCongruencesRec(prog,fn,contBlock,cont.childContext(execCx),blockState,result);
    if (unifyBranches) {
      branchStates.add(blockState);
    }
  }
  if (unifyBranches) {
    return UnifiedValues.unify(logger,prog.constants(),fn,reorderingAllowed,stmtIndex,state,cont,branchStates,cont.getBlocks());
  }
 else {
    return UnifiedValues.EMPTY;
  }
}

Fixed version (ground truth):
private UnifiedValues findCongruencesContRec(Program prog,Function fn,ExecContext execCx,Continuation cont,int stmtIndex,Congruences state,Map<Block,Congruences> result){
  logger.trace("String_Node_Str" + cont.getType());
  Congruences contState=state.enterContinuation(cont.inheritsParentVars(),stmtIndex);
  List<BlockingVar> contClosedVars=cont.blockingVars(true);
  if (contClosedVars != null) {
    for (    BlockingVar bv : contClosedVars) {
      int contStmtIndex=0;
      contState.markClosed(bv.var,contStmtIndex,bv.recursive);
    }
  }
  boolean unifyBranches=cont.isExhaustiveSyncConditional();
  List<Congruences> branchStates=unifyBranches ? new ArrayList<Congruences>() : null;
  for (  Block contBlock : cont.getBlocks()) {
    Congruences blockState=contState.enterBlock();
    findCongruencesRec(prog,fn,contBlock,cont.childContext(execCx),blockState,result);
    if (unifyBranches) {
      branchStates.add(blockState);
    }
  }
  if (unifyBranches) {
    return UnifiedValues.unify(logger,prog.constants(),fn,reorderingAllowed,stmtIndex,state,cont,branchStates,cont.getBlocks());
  }
 else {
    return UnifiedValues.EMPTY;
  }
}
Program: 132901
Project: 132901
Buggy source:
/** 
 * Check if variable is directly closed. Returns a matching entry 
 * @param var
 * @param recursive
 * @param stmtIndex
 * @return
 */
private ClosedEntry getDirectClosedEntry(Var var,boolean recursive,int stmtIndex){
  ClosedVarTracker curr=this;
  int currStmtIndex=stmtIndex;
  while (curr != null) {
    for (    ClosedEntry ce : curr.closed.get(var)) {
      if (ce.matches(recursive,currStmtIndex)) {
        if (curr == this) {
          return ce;
        }
 else {
          ClosedEntry origScopeEntry=new ClosedEntry(0,ce.recursive);
          closed.put(var,origScopeEntry);
          return origScopeEntry;
        }
      }
    }
    currStmtIndex=curr.parentStmtIndex;
    curr=curr.parent;
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Check if variable is directly closed. Returns a matching entry 
 * @param var
 * @param recursive
 * @param stmtIndex
 * @return
 */
private ClosedEntry getDirectClosedEntry(Var var,boolean recursive,int stmtIndex){
  ClosedVarTracker curr=this;
  int currStmtIndex=stmtIndex;
  while (curr != null) {
    for (    ClosedEntry ce : curr.closed.get(var)) {
      logger.trace(var + "String_Node_Str" + ce+ "String_Node_Str"+ recursive+ "String_Node_Str"+ currStmtIndex);
      if (ce.matches(recursive,currStmtIndex)) {
        if (curr == this) {
          return ce;
        }
 else {
          ClosedEntry origScopeEntry=new ClosedEntry(0,ce.recursive);
          closed.put(var,origScopeEntry);
          return origScopeEntry;
        }
      }
    }
    currStmtIndex=curr.parentStmtIndex;
    curr=curr.parent;
  }
  return null;
}
Program: 132902
Project: 132902
Buggy source:
/** 
 * Merge two congruence sets that are newly connected via value
 * @param errContext
 * @param resVal
 * @param congruent
 * @param newLoc representative of set with location just assigned
 * @param oldLoc representative of existing set
 */
private void mergeSets(String errContext,RecCV value,GlobalConstants consts,CongruentSets congruent,Arg newLoc,Arg oldLoc,int stmtIndex){
  if (newLoc.equals(oldLoc)) {
    return;
  }
  if (!checkNoContradiction(errContext,congruent.congType,value,newLoc,oldLoc)) {
    congruent.markContradiction(newLoc);
    congruent.markContradiction(oldLoc);
  }
  Arg winner=preferred(congruent,oldLoc,newLoc,stmtIndex);
  Arg loser=(winner == oldLoc ? newLoc : oldLoc);
  changeCanonical(consts,congruent,loser,winner);
}

Fixed version (ground truth):
/** 
 * Merge two congruence sets that are newly connected via value
 * @param errContext
 * @param resVal
 * @param congruent
 * @param newLoc representative of set with location just assigned
 * @param oldLoc representative of existing set
 */
private void mergeSets(String errContext,RecCV value,GlobalConstants consts,CongruentSets congruent,Arg newLoc,Arg oldLoc,int stmtIndex){
  if (newLoc.equals(oldLoc)) {
    return;
  }
  if (!checkNoContradiction(errContext,congruent.congType,value,newLoc,oldLoc)) {
    congruent.markContradiction(newLoc);
    congruent.markContradiction(oldLoc);
  }
  Arg winner=preferred(congruent,oldLoc,newLoc,stmtIndex);
  Arg loser=(winner == oldLoc ? newLoc : oldLoc);
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + oldLoc + "String_Node_Str"+ newLoc+ "String_Node_Str"+ winner);
  }
  changeCanonical(consts,congruent,loser,winner);
}
Program: 132903
Project: 132903
Buggy source:
private boolean isClosed(Arg varArg,int stmtIndex,boolean recursive){
  if (varArg.isConstant() || !trackClosed(varArg.getVar())) {
    logger.trace(varArg + "String_Node_Str");
    return true;
  }
  Var canonicalAlias=getCanonicalAlias(varArg);
  ClosedEntry canonicalClosed;
  canonicalClosed=isClosedNonAlias(canonicalAlias,stmtIndex,recursive);
  if (canonicalClosed != null && canonicalClosed.matches(recursive,stmtIndex)) {
    logger.trace(varArg + "String_Node_Str" + canonicalClosed.stmtIndex);
    return true;
  }
  for (  Arg mergedSet : byAlias.allMergedCanonicals(canonicalAlias.asArg())) {
    assert(mergedSet.isVar());
    Var merged=mergedSet.getVar();
    ClosedEntry ce=isClosedNonAlias(merged,stmtIndex,recursive);
    if (ce != null) {
      track.close(canonicalAlias,ce);
      if (ce.matches(recursive,stmtIndex)) {
        logger.trace(varArg + "String_Node_Str" + canonicalClosed.stmtIndex+ "String_Node_Str"+ merged);
        return true;
      }
    }
  }
  return false;
}

Fixed version (ground truth):
private boolean isClosed(Arg varArg,int stmtIndex,boolean recursive){
  if (varArg.isConstant() || !trackClosed(varArg.getVar())) {
    logger.trace(varArg + "String_Node_Str");
    return true;
  }
  Var canonicalAlias=getCanonicalAlias(varArg);
  ClosedEntry ce;
  ce=isClosedNonAlias(canonicalAlias,stmtIndex,recursive);
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + varArg + "String_Node_Str"+ canonicalAlias+ "String_Node_Str"+ ce);
  }
  if (ce != null && ce.matches(recursive,stmtIndex)) {
    logger.trace(varArg + "String_Node_Str" + ce.stmtIndex);
    return true;
  }
  for (  Arg mergedSet : byAlias.allMergedCanonicals(canonicalAlias.asArg())) {
    assert(mergedSet.isVar());
    Var merged=mergedSet.getVar();
    isClosedNonAlias(merged,stmtIndex,recursive);
    if (logger.isTraceEnabled()) {
      logger.trace("String_Node_Str" + varArg + "String_Node_Str"+ mergedSet+ "String_Node_Str"+ ce);
    }
    if (ce != null) {
      track.close(canonicalAlias,ce);
      if (ce.matches(recursive,stmtIndex)) {
        logger.trace(varArg + "String_Node_Str" + ce.stmtIndex+ "String_Node_Str"+ merged);
        return true;
      }
    }
  }
  return false;
}
Program: 132904
Project: 132904
Buggy source:
@Override public Map<String,Type> matchTypeVars(Type concrete){
  return baseType.matchTypeVars(concrete);
}

Fixed version (ground truth):
@Override public Map<String,Type> matchTypeVars(Type concrete){
  while (concrete instanceof SubType) {
    if (this.equals(concrete)) {
      break;
    }
 else {
      concrete=((SubType)concrete).baseType();
    }
  }
  return baseType.matchTypeVars(concrete);
}
Program: 132905
Project: 132905
Buggy source:
/** 
 * Initialise a local file with a filename
 * @param localFile
 * @param filenameVal
 */
public void initLocalOutputFile(Var localFile,Arg filenameVal);

Fixed version (ground truth):
/** 
 * Initialise a local file with a filename
 * @param localFile an uninitialized local file var
 * @param filenameVal an immediate string containing the filename
 * @param isMapped an immediate bool saying whether the file is mapped- i.e. whether it must be retained in all cases
 */
public void initLocalOutputFile(Var localFile,Arg filenameVal,Arg isMapped);
Program: 132906
Project: 132906
Buggy source:
public static SetVariable createLocalFile(String varName,Expression fileName){
  return new SetVariable(varName,new Square(CREATE_LOCAL_FILE_REF,fileName));
}

Fixed version (ground truth):
public static SetVariable createLocalFile(String varName,Expression fileName,Expression initRefcount){
  return new SetVariable(varName,new Square(CREATE_LOCAL_FILE_REF,fileName,initRefcount));
}
Program: 132907
Project: 132907
Buggy source:
@Override public void initLocalOutputFile(Var localFile,Arg filenameVal){
  assert(localFile.type().assignableTo(Types.V_FILE));
  assert(filenameVal.type().assignableTo(Types.V_STRING));
  pointStack.peek().add(Turbine.createLocalFile(prefixVar(localFile),argToExpr(filenameVal)));
}

Fixed version (ground truth):
@Override public void initLocalOutputFile(Var localFile,Arg filenameVal,Arg isMapped){
  assert(localFile.type().assignableTo(Types.V_FILE));
  assert(filenameVal.isImmediateString());
  assert(isMapped.isImmediateBool());
  Sequence ifMapped=new Sequence(), ifUnmapped=new Sequence();
  ifMapped.add(new SetVariable(TCLTMP_INIT_REFCOUNT,LiteralInt.TWO));
  ifUnmapped.add(new SetVariable(TCLTMP_INIT_REFCOUNT,LiteralInt.ONE));
  pointStack.peek().add(new If(argToExpr(isMapped),ifMapped,ifUnmapped));
  pointStack.peek().add(Turbine.createLocalFile(prefixVar(localFile),argToExpr(filenameVal),new Value(TCLTMP_INIT_REFCOUNT)));
}
Program: 132908
Project: 132908
Buggy source:
/** 
 * Initialize the context and define the two variables: for array member and (optionally) for the loop count
 * @param context
 * @param rangeLoop where a range loop or container
 * @param includeIndexFuture if true, initialize the count var(getCountVarName()), rather than just loopCountval
 * @return
 * @throws UserException
 */
public Context setupLoopBodyContext(Context context,boolean rangeLoop,boolean includeIndexFuture) throws UserException {
  Type arrayType=findArrayType(context);
  loopBodyContext=new LocalContext(context);
  if (countVarName != null) {
    keyType=Types.arrayKeyType(arrayType);
    Type keyValType=Types.derefResultType(keyType);
    loopCountVal=context.createLocalValueVariable(keyValType,countVarName);
    if (includeIndexFuture) {
      Var loopCountVar=createCountVar();
      context.declareVariable(loopCountVar.type(),loopCountVar.name(),loopCountVar.storage(),loopCountVar.defType(),loopCountVar.mapping());
    }
  }
 else {
    loopCountVal=null;
  }
  VarStorage memberVarStorage=rangeLoop ? VarStorage.TEMP : VarStorage.ALIAS;
  memberVar=loopBodyContext.declareVariable(Types.arrayMemberType(arrayType),getMemberVarName(),memberVarStorage,DefType.LOCAL_USER,null);
  return loopBodyContext;
}

Fixed version (ground truth):
/** 
 * Initialize the context and define the two variables: for array member and (optionally) for the loop count
 * @param context
 * @param rangeLoop where a range loop or container
 * @param includeIndexFuture if true, initialize the count var(getCountVarName()), rather than just loopCountval
 * @return
 * @throws UserException
 */
public Context setupLoopBodyContext(Context context,boolean rangeLoop,boolean includeIndexFuture) throws UserException {
  Type arrayType=findArrayType(context);
  loopBodyContext=new LocalContext(context);
  if (countVarName != null) {
    keyType=Types.arrayKeyType(arrayType);
    Type keyValType=Types.derefResultType(keyType);
    loopCountVal=context.createLocalValueVariable(keyValType,countVarName);
    if (includeIndexFuture) {
      Var countVar=createCountVar();
      loopBodyContext.declareVariable(countVar.type(),countVar.name(),countVar.storage(),countVar.defType(),countVar.mapping());
    }
  }
 else {
    loopCountVal=null;
  }
  VarStorage memberVarStorage=rangeLoop ? VarStorage.TEMP : VarStorage.ALIAS;
  memberVar=loopBodyContext.declareVariable(Types.arrayMemberType(arrayType),getMemberVarName(),memberVarStorage,DefType.LOCAL_USER,null);
  return loopBodyContext;
}
Program: 132910
Project: 132910
Buggy source:
public static VariableDescriptor fromDeclareVariableRest(Context context,Type baseType,SwiftAST tree) throws UndefinedTypeException, InvalidSyntaxException {
  assert(tree.getType() == ExMParser.DECLARE_VARIABLE_REST);
  assert(tree.getChildCount() >= 1);
  SwiftAST nameTree=tree.child(0);
  assert(nameTree.getType() == ExMParser.ID);
  String varName=nameTree.getText();
  SwiftAST mappingExpr=null;
  Type varType=baseType;
  for (  SwiftAST subtree : tree.children(1)) {
    if (subtree.getType() == ExMParser.ARRAY) {
      Type keyType=getArrayKeyType(context,subtree);
      varType=new Types.ArrayType(keyType,varType);
    }
 else     if (subtree.getType() == ExMParser.MAPPING) {
      assert(mappingExpr == null);
      assert(subtree.getChildCount() == 1);
      mappingExpr=subtree.child(0);
    }
 else {
      throw new STCRuntimeError("String_Node_Str" + "String_Node_Str" + LogHelper.tokName(subtree.getType()));
    }
  }
  return new VariableDescriptor(varType,varName,mappingExpr);
}

Fixed version (ground truth):
public static VariableDescriptor fromDeclareVariableRest(Context context,Type baseType,SwiftAST tree) throws UndefinedTypeException, InvalidSyntaxException {
  assert(tree.getType() == ExMParser.DECLARE_VARIABLE_REST);
  assert(tree.getChildCount() >= 1);
  SwiftAST nameTree=tree.child(0);
  assert(nameTree.getType() == ExMParser.ID);
  String varName=nameTree.getText();
  SwiftAST mappingExpr=null;
  Type varType=baseType;
  for (int i=tree.getChildCount() - 1; i >= 1; i--) {
    SwiftAST subtree=tree.child(i);
    if (subtree.getType() == ExMParser.ARRAY) {
      Type keyType=getArrayKeyType(context,subtree);
      varType=new Types.ArrayType(keyType,varType);
    }
 else     if (subtree.getType() == ExMParser.MAPPING) {
      assert(mappingExpr == null);
      assert(subtree.getChildCount() == 1);
      mappingExpr=subtree.child(0);
    }
 else {
      throw new STCRuntimeError("String_Node_Str" + "String_Node_Str" + LogHelper.tokName(subtree.getType()));
    }
  }
  return new VariableDescriptor(varType,varName,mappingExpr);
}