Program: 132532
Project: 132532
Buggy source:
public static TclTree genLocalOpTcl(BuiltinOpcode op,Var out,List<Arg> in,ArrayList<Expression> argExpr){
  if (op == BuiltinOpcode.ASSERT || op == BuiltinOpcode.ASSERT_EQ) {
    assert(out != null && Types.isVoidVal(out));
    Token tclFn;
switch (op) {
case ASSERT:
      tclFn=Turbine.TURBINE_ASSERT_IMPL;
    break;
case ASSERT_EQ:
  tclFn=Turbine.TURBINE_ASSERT_EQUAL_IMPL;
break;
default :
throw new STCRuntimeError("String_Node_Str" + op.toString());
}
return new Command(tclFn,argExpr);
}
 else {
if (op == BuiltinOpcode.SPRINTF) {
Square fmtArgs=new TclList(argExpr);
Square fmt=new Square(new Token("String_Node_Str"),new Token("String_Node_Str"),fmtArgs);
return new SetVariable(TclNamer.prefixVar(out.name()),fmt);
}
 else {
assert(out != null);
assert(Types.isPrimValue(out));
Expression rhs;
if (op == BuiltinOpcode.STRCAT) {
rhs=localStrCat(in,argExpr);
}
 else if (op == BuiltinOpcode.DIRCAT) {
rhs=localDirCat(in,argExpr);
}
 else if (op == BuiltinOpcode.EQ_STRING || op == BuiltinOpcode.NEQ_STRING) {
assert(argExpr.size() == 2);
Expression s1=argExpr.get(0);
Expression s2=argExpr.get(1);
rhs=Turbine.stringEqual(s1,s2);
if (op == BuiltinOpcode.NEQ_STRING) {
rhs=new TclExpr(true,TclExpr.NOT,rhs);
}
}
 else if (op == BuiltinOpcode.COPY_BLOB || op == BuiltinOpcode.COPY_BOOL || op == BuiltinOpcode.COPY_INT || op == BuiltinOpcode.COPY_VOID || op == BuiltinOpcode.COPY_FLOAT || op == BuiltinOpcode.COPY_STRING) {
assert(argExpr.size() == 1);
checkCopy(op,out,in.get(0));
rhs=argExpr.get(0);
}
 else if (op == BuiltinOpcode.MOD_INT) {
rhs=Turbine.modInteger(argExpr.get(0),argExpr.get(1));
}
 else if (op == BuiltinOpcode.DIV_INT) {
rhs=Turbine.divideInteger(argExpr.get(0),argExpr.get(1));
}
 else if (op == BuiltinOpcode.POW_INT) {
assert(argExpr.size() == 2);
assert(in.get(0).isImmInt() && in.get(1).isImmInt());
rhs=new Square(Turbine.POW_INTEGER_IMPL,argExpr.get(0),argExpr.get(1));
}
 else if (op == BuiltinOpcode.SUBSTRING) {
assert(argExpr.size() == 3);
rhs=new Square(Turbine.SUBSTRING_IMPL,argExpr.get(0),argExpr.get(1),argExpr.get(2));
}
 else if (op == BuiltinOpcode.INTTOSTR || op == BuiltinOpcode.FLOATTOSTR) {
assert(argExpr.size() == 1);
rhs=argExpr.get(0);
}
 else if (op == BuiltinOpcode.PARSE_INT) {
assert(argExpr.size() == 2);
rhs=Square.fnCall(Turbine.PARSE_INT,argExpr.get(0),argExpr.get(1));
}
 else if (op == BuiltinOpcode.PARSE_FLOAT) {
assert(argExpr.size() == 1);
rhs=Square.fnCall(Turbine.TOFLOAT_IMPL,argExpr.get(0),argExpr.get(1));
}
 else {
Expression exp[]=arithOpExpr(op,argExpr);
rhs=new TclExpr(exp);
}
return new SetVariable(TclNamer.prefixVar(out.name()),rhs);
}
}
}

Fixed version (ground truth):
public static TclTree genLocalOpTcl(BuiltinOpcode op,Var out,List<Arg> in,ArrayList<Expression> argExpr){
  if (op == BuiltinOpcode.ASSERT || op == BuiltinOpcode.ASSERT_EQ) {
    assert(out != null && Types.isVoidVal(out));
    Token tclFn;
switch (op) {
case ASSERT:
      tclFn=Turbine.TURBINE_ASSERT_IMPL;
    break;
case ASSERT_EQ:
  tclFn=Turbine.TURBINE_ASSERT_EQUAL_IMPL;
break;
default :
throw new STCRuntimeError("String_Node_Str" + op.toString());
}
return new Command(tclFn,argExpr);
}
 else {
if (op == BuiltinOpcode.SPRINTF) {
Square fmtArgs=new TclList(argExpr);
Square fmt=new Square(new Token("String_Node_Str"),new Token("String_Node_Str"),fmtArgs);
return new SetVariable(TclNamer.prefixVar(out.name()),fmt);
}
 else {
assert(out != null);
assert(Types.isPrimValue(out));
Expression rhs;
if (op == BuiltinOpcode.STRCAT) {
rhs=localStrCat(in,argExpr);
}
 else if (op == BuiltinOpcode.DIRCAT) {
rhs=localDirCat(in,argExpr);
}
 else if (op == BuiltinOpcode.EQ_STRING || op == BuiltinOpcode.NEQ_STRING) {
assert(argExpr.size() == 2);
Expression s1=argExpr.get(0);
Expression s2=argExpr.get(1);
rhs=Turbine.stringEqual(s1,s2);
if (op == BuiltinOpcode.NEQ_STRING) {
rhs=new TclExpr(true,TclExpr.NOT,rhs);
}
}
 else if (op == BuiltinOpcode.COPY_BLOB || op == BuiltinOpcode.COPY_BOOL || op == BuiltinOpcode.COPY_INT || op == BuiltinOpcode.COPY_VOID || op == BuiltinOpcode.COPY_FLOAT || op == BuiltinOpcode.COPY_STRING) {
assert(argExpr.size() == 1);
checkCopy(op,out,in.get(0));
rhs=argExpr.get(0);
}
 else if (op == BuiltinOpcode.MOD_INT) {
rhs=Turbine.modInteger(argExpr.get(0),argExpr.get(1));
}
 else if (op == BuiltinOpcode.DIV_INT) {
rhs=Turbine.divideInteger(argExpr.get(0),argExpr.get(1));
}
 else if (op == BuiltinOpcode.POW_INT) {
assert(argExpr.size() == 2);
assert(in.get(0).isImmInt() && in.get(1).isImmInt());
rhs=new Square(Turbine.POW_INTEGER_IMPL,argExpr.get(0),argExpr.get(1));
}
 else if (op == BuiltinOpcode.SUBSTRING) {
assert(argExpr.size() == 3);
rhs=new Square(Turbine.SUBSTRING_IMPL,argExpr.get(0),argExpr.get(1),argExpr.get(2));
}
 else if (op == BuiltinOpcode.INTTOSTR || op == BuiltinOpcode.FLOATTOSTR) {
assert(argExpr.size() == 1);
rhs=argExpr.get(0);
}
 else if (op == BuiltinOpcode.PARSE_INT) {
assert(argExpr.size() == 2);
rhs=Square.fnCall(Turbine.PARSE_INT,argExpr.get(0),argExpr.get(1));
}
 else if (op == BuiltinOpcode.PARSE_FLOAT) {
assert(argExpr.size() == 1);
rhs=Square.fnCall(Turbine.TOFLOAT_IMPL,argExpr.get(0));
}
 else {
Expression exp[]=arithOpExpr(op,argExpr);
rhs=new TclExpr(exp);
}
return new SetVariable(TclNamer.prefixVar(out.name()),rhs);
}
}
}