Program: 110828
Project: 110828
Buggy source:
/** 
 * Given 'temps', traverse this target and its dependencies and collect up all the object files, libraries, linker options, linkstamps attributes and linker scripts.
 */
private static CppLinkActionBuilder determineLinkerArguments(RuleContext context,CcCommon common,PrecompiledFiles precompiledFiles,CcLibraryHelper.Info info,ImmutableSet<Artifact> compilationPrerequisites,boolean fake,Artifact binary,LinkStaticness linkStaticness,List<String> linkopts) throws InterruptedException {
  CppLinkActionBuilder builder=new CppLinkActionBuilder(context,binary).setCrosstoolInputs(CppHelper.getToolchain(context).getLink()).addNonCodeInputs(compilationPrerequisites);
  CppConfiguration cppConfiguration=context.getFragment(CppConfiguration.class);
  if (cppConfiguration.getLinkDynamicBinariesSeparately() && linkStaticness == LinkStaticness.DYNAMIC) {
    for (    LibraryToLink library : info.getCcLinkingOutputs().getDynamicLibraries()) {
      builder.addLibrary(library);
    }
  }
 else {
    boolean usePic=CppHelper.usePic(context,!isLinkShared(context));
    Iterable<Artifact> objectFiles=info.getCcCompilationOutputs().getObjectFiles(usePic);
    if (fake) {
      builder.addFakeObjectFiles(objectFiles);
    }
 else {
      builder.addObjectFiles(objectFiles);
    }
  }
  builder.addLTOBitcodeFiles(info.getCcCompilationOutputs().getLtoBitcodeFiles());
  builder.addNonCodeInputs(common.getLinkerScripts());
  for (  Artifact library : precompiledFiles.getLibraries()) {
    if (Link.SHARED_LIBRARY_FILETYPES.matches(library.getFilename())) {
      builder.addLibrary(LinkerInputs.solibLibraryToLink(common.getDynamicLibrarySymlink(library,true),library,CcLinkingOutputs.libraryIdentifierOf(library)));
    }
 else     if (Link.LINK_LIBRARY_FILETYPES.matches(library.getFilename())) {
      builder.addLibrary(LinkerInputs.precompiledLibraryToLink(library,ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY));
    }
 else     if (Link.ARCHIVE_FILETYPES.matches(library.getFilename())) {
      builder.addLibrary(LinkerInputs.precompiledLibraryToLink(library,ArtifactCategory.STATIC_LIBRARY));
    }
 else {
      throw new IllegalStateException();
    }
  }
  CcLinkParams linkParams=collectCcLinkParams(context,linkStaticness != LinkStaticness.DYNAMIC,isLinkShared(context),linkopts);
  builder.addLinkParams(linkParams,context);
  return builder;
}

Fixed version (ground truth):
/** 
 * Given 'temps', traverse this target and its dependencies and collect up all the object files, libraries, linker options, linkstamps attributes and linker scripts.
 */
private static CppLinkActionBuilder determineLinkerArguments(RuleContext context,CcCommon common,PrecompiledFiles precompiledFiles,CcLibraryHelper.Info info,ImmutableSet<Artifact> compilationPrerequisites,boolean fake,Artifact binary,LinkStaticness linkStaticness,List<String> linkopts,boolean linkCompileOutputSeparately) throws InterruptedException {
  CppLinkActionBuilder builder=new CppLinkActionBuilder(context,binary).setCrosstoolInputs(CppHelper.getToolchain(context).getLink()).addNonCodeInputs(compilationPrerequisites);
  if (linkCompileOutputSeparately) {
    for (    LibraryToLink library : info.getCcLinkingOutputs().getDynamicLibraries()) {
      builder.addLibrary(library);
    }
  }
 else {
    boolean usePic=CppHelper.usePic(context,!isLinkShared(context));
    Iterable<Artifact> objectFiles=info.getCcCompilationOutputs().getObjectFiles(usePic);
    if (fake) {
      builder.addFakeObjectFiles(objectFiles);
    }
 else {
      builder.addObjectFiles(objectFiles);
    }
  }
  builder.addLTOBitcodeFiles(info.getCcCompilationOutputs().getLtoBitcodeFiles());
  builder.addNonCodeInputs(common.getLinkerScripts());
  for (  Artifact library : precompiledFiles.getLibraries()) {
    if (Link.SHARED_LIBRARY_FILETYPES.matches(library.getFilename())) {
      builder.addLibrary(LinkerInputs.solibLibraryToLink(common.getDynamicLibrarySymlink(library,true),library,CcLinkingOutputs.libraryIdentifierOf(library)));
    }
 else     if (Link.LINK_LIBRARY_FILETYPES.matches(library.getFilename())) {
      builder.addLibrary(LinkerInputs.precompiledLibraryToLink(library,ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY));
    }
 else     if (Link.ARCHIVE_FILETYPES.matches(library.getFilename())) {
      builder.addLibrary(LinkerInputs.precompiledLibraryToLink(library,ArtifactCategory.STATIC_LIBRARY));
    }
 else {
      throw new IllegalStateException();
    }
  }
  CcLinkParams linkParams=collectCcLinkParams(context,linkStaticness != LinkStaticness.DYNAMIC,isLinkShared(context),linkopts);
  builder.addLinkParams(linkParams,context);
  return builder;
}