Program: 132754
Project: 132754
Buggy source:
private void defineBuiltinFunction(Context context,SwiftAST tree) throws UserException {
  final int REQUIRED_CHILDREN=5;
  assert(tree.getChildCount() >= REQUIRED_CHILDREN);
  String function=tree.child(0).getText();
  SwiftAST typeParamsT=tree.child(1);
  SwiftAST outputs=tree.child(2);
  SwiftAST inputs=tree.child(3);
  SwiftAST tclPackage=tree.child(4);
  assert(inputs.getType() == ExMParser.FORMAL_ARGUMENT_LIST);
  assert(outputs.getType() == ExMParser.FORMAL_ARGUMENT_LIST);
  assert(tclPackage.getType() == ExMParser.TCL_PACKAGE);
  assert(tclPackage.getChildCount() == 2);
  Set<String> typeParams=extractTypeParams(typeParamsT);
  FunctionDecl fdecl=FunctionDecl.fromAST(context,function,inputs,outputs,typeParams);
  FunctionType ft=fdecl.getFunctionType();
  LogHelper.debug(context,"String_Node_Str" + function + "String_Node_Str"+ ft);
  String pkg=Literals.extractLiteralString(context,tclPackage.child(0));
  String version=Literals.extractLiteralString(context,tclPackage.child(1));
  backend.requirePackage(pkg,version);
  int pos=REQUIRED_CHILDREN;
  TclFunRef impl=null;
  if (pos < tree.getChildCount() && tree.child(pos).getType() == ExMParser.TCL_FUN_REF) {
    SwiftAST tclImplRef=tree.child(pos);
    String symbol=Literals.extractLiteralString(context,tclImplRef.child(0));
    impl=new TclFunRef(pkg,symbol,version);
    pos++;
  }
  TclOpTemplate inlineTcl=null;
  if (pos < tree.getChildCount() && tree.child(pos).getType() == ExMParser.INLINE_TCL) {
    SwiftAST inlineTclTree=tree.child(pos);
    inlineTcl=wrapper.loadTclTemplate(context,function,fdecl,ft,inlineTclTree);
    pos++;
  }
  for (; pos < tree.getChildCount(); pos++) {
    handleBuiltinFunctionAnnotation(context,function,fdecl,tree.child(pos),inlineTcl != null);
  }
  TaskMode taskMode=ForeignFunctions.getTaskMode(function);
  boolean isTargetable=false;
  if (!taskMode.isLocal()) {
    isTargetable=true;
    context.setFunctionProperty(function,FnProp.TARGETABLE);
  }
  context.defineFunction(function,ft);
  FunctionType backendFT=VarRepr.backendFnType(ft);
  if (impl != null) {
    context.setFunctionProperty(function,FnProp.BUILTIN);
    backend.defineBuiltinFunction(function,backendFT,impl);
  }
 else {
    if (inlineTcl == null) {
      throw new UserException(context,"String_Node_Str" + "String_Node_Str" + function);
    }
    context.setFunctionProperty(function,FnProp.WRAPPED_BUILTIN);
    context.setFunctionProperty(function,FnProp.SYNC);
    boolean isParallel=context.hasFunctionProp(function,FnProp.PARALLEL);
    if (isParallel && taskMode != TaskMode.WORKER) {
      throw new UserException(context,"String_Node_Str");
    }
    wrapper.saveWrapper(function,backendFT,fdecl,taskMode,isParallel,isTargetable);
  }
}

Fixed version (ground truth):
private void defineBuiltinFunction(Context context,SwiftAST tree) throws UserException {
  final int REQUIRED_CHILDREN=5;
  assert(tree.getChildCount() >= REQUIRED_CHILDREN);
  String function=tree.child(0).getText();
  SwiftAST typeParamsT=tree.child(1);
  SwiftAST outputs=tree.child(2);
  SwiftAST inputs=tree.child(3);
  SwiftAST tclPackage=tree.child(4);
  assert(inputs.getType() == ExMParser.FORMAL_ARGUMENT_LIST);
  assert(outputs.getType() == ExMParser.FORMAL_ARGUMENT_LIST);
  assert(tclPackage.getType() == ExMParser.TCL_PACKAGE);
  assert(tclPackage.getChildCount() == 2);
  Set<String> typeParams=extractTypeParams(typeParamsT);
  FunctionDecl fdecl=FunctionDecl.fromAST(context,function,inputs,outputs,typeParams);
  FunctionType ft=fdecl.getFunctionType();
  LogHelper.debug(context,"String_Node_Str" + function + "String_Node_Str"+ ft);
  String pkg=Literals.extractLiteralString(context,tclPackage.child(0));
  String version=Literals.extractLiteralString(context,tclPackage.child(1));
  backend.requirePackage(pkg,version);
  int pos=REQUIRED_CHILDREN;
  TclFunRef impl=null;
  if (pos < tree.getChildCount() && tree.child(pos).getType() == ExMParser.TCL_FUN_REF) {
    SwiftAST tclImplRef=tree.child(pos);
    String symbol=Literals.extractLiteralString(context,tclImplRef.child(0));
    impl=new TclFunRef(pkg,symbol,version);
    pos++;
  }
  TclOpTemplate inlineTcl=null;
  if (pos < tree.getChildCount() && tree.child(pos).getType() == ExMParser.INLINE_TCL) {
    SwiftAST inlineTclTree=tree.child(pos);
    inlineTcl=wrapper.loadTclTemplate(context,function,fdecl,ft,inlineTclTree);
    pos++;
  }
  ForeignFunctions.addForeignFunction(function);
  for (; pos < tree.getChildCount(); pos++) {
    handleBuiltinFunctionAnnotation(context,function,fdecl,tree.child(pos),inlineTcl != null);
  }
  TaskMode taskMode=ForeignFunctions.getTaskMode(function);
  boolean isTargetable=false;
  if (!taskMode.isLocal()) {
    isTargetable=true;
    context.setFunctionProperty(function,FnProp.TARGETABLE);
  }
  context.defineFunction(function,ft);
  FunctionType backendFT=VarRepr.backendFnType(ft);
  if (impl != null) {
    context.setFunctionProperty(function,FnProp.BUILTIN);
    backend.defineBuiltinFunction(function,backendFT,impl);
  }
 else {
    if (inlineTcl == null) {
      throw new UserException(context,"String_Node_Str" + "String_Node_Str" + function);
    }
    context.setFunctionProperty(function,FnProp.WRAPPED_BUILTIN);
    context.setFunctionProperty(function,FnProp.SYNC);
    boolean isParallel=context.hasFunctionProp(function,FnProp.PARALLEL);
    if (isParallel && taskMode != TaskMode.WORKER) {
      throw new UserException(context,"String_Node_Str");
    }
    wrapper.saveWrapper(function,backendFT,fdecl,taskMode,isParallel,isTargetable);
  }
}