Program: 110827
Project: 110827
Buggy source:
private static Runfiles collectRunfiles(RuleContext context,CcLinkingOutputs linkingOutputs,CcLibraryHelper.Info info,LinkStaticness linkStaticness,NestedSet<Artifact> filesToBuild,Iterable<Artifact> fakeLinkerInputs,boolean fake,ImmutableSet<CppSource> cAndCppSources){
  Runfiles.Builder builder=new Runfiles.Builder(context.getWorkspaceName(),context.getConfiguration().legacyExternalRunfiles());
  Function<TransitiveInfoCollection,Runfiles> runfilesMapping=CppRunfilesProvider.runfilesFunction(linkStaticness != LinkStaticness.DYNAMIC);
  builder.addTransitiveArtifacts(filesToBuild);
  builder.addArtifacts(linkingOutputs.getLibrariesForRunfiles(true));
  builder.addRunfiles(context,RunfilesProvider.DEFAULT_RUNFILES);
  builder.add(context,runfilesMapping);
  CcToolchainProvider toolchain=CppHelper.getToolchain(context);
  if (linkStaticness == LinkStaticness.DYNAMIC) {
    builder.addTransitiveArtifacts(toolchain.getDynamicRuntimeLinkInputs());
    CppConfiguration cppConfiguration=context.getFragment(CppConfiguration.class);
    if (cppConfiguration.getLinkDynamicBinariesSeparately()) {
      builder.addArtifacts(LinkerInputs.toLibraryArtifacts(info.getCcLinkingOutputs().getExecutionDynamicLibraries()));
    }
  }
  boolean linkshared=isLinkShared(context);
  if (!linkshared) {
    TransitiveInfoCollection malloc=CppHelper.mallocForTarget(context);
    builder.addTarget(malloc,RunfilesProvider.DEFAULT_RUNFILES);
    builder.addTarget(malloc,runfilesMapping);
  }
  if (fake) {
    builder.addSymlinksToArtifacts(Iterables.filter(fakeLinkerInputs,Artifact.MIDDLEMAN_FILTER));
    builder.addTransitiveArtifacts(toolchain.getCrosstool());
    builder.addTransitiveArtifacts(toolchain.getLibcLink());
    ImmutableSet.Builder<Artifact> sourcesBuilder=ImmutableSet.<Artifact>builder();
    for (    CppSource cppSource : cAndCppSources) {
      sourcesBuilder.add(cppSource.getSource());
    }
    builder.addSymlinksToArtifacts(sourcesBuilder.build());
    CppCompilationContext cppCompilationContext=info.getCppCompilationContext();
    builder.addSymlinksToArtifacts(cppCompilationContext.getDeclaredIncludeSrcs());
    builder.addSymlinksToArtifacts(cppCompilationContext.getAdditionalInputs());
    builder.addSymlinksToArtifacts(cppCompilationContext.getTransitiveModules(CppHelper.usePic(context,!isLinkShared(context))));
  }
  return builder.build();
}

Fixed version (ground truth):
private static Runfiles collectRunfiles(RuleContext context,CcLinkingOutputs linkingOutputs,CcLibraryHelper.Info info,LinkStaticness linkStaticness,NestedSet<Artifact> filesToBuild,Iterable<Artifact> fakeLinkerInputs,boolean fake,ImmutableSet<CppSource> cAndCppSources,boolean linkCompileOutputSeparately){
  Runfiles.Builder builder=new Runfiles.Builder(context.getWorkspaceName(),context.getConfiguration().legacyExternalRunfiles());
  Function<TransitiveInfoCollection,Runfiles> runfilesMapping=CppRunfilesProvider.runfilesFunction(linkStaticness != LinkStaticness.DYNAMIC);
  builder.addTransitiveArtifacts(filesToBuild);
  builder.addArtifacts(linkingOutputs.getLibrariesForRunfiles(true));
  builder.addRunfiles(context,RunfilesProvider.DEFAULT_RUNFILES);
  builder.add(context,runfilesMapping);
  CcToolchainProvider toolchain=CppHelper.getToolchain(context);
  if (linkStaticness == LinkStaticness.DYNAMIC) {
    builder.addTransitiveArtifacts(toolchain.getDynamicRuntimeLinkInputs());
  }
  if (linkCompileOutputSeparately) {
    builder.addArtifacts(LinkerInputs.toLibraryArtifacts(info.getCcLinkingOutputs().getExecutionDynamicLibraries()));
  }
  boolean linkshared=isLinkShared(context);
  if (!linkshared) {
    TransitiveInfoCollection malloc=CppHelper.mallocForTarget(context);
    builder.addTarget(malloc,RunfilesProvider.DEFAULT_RUNFILES);
    builder.addTarget(malloc,runfilesMapping);
  }
  if (fake) {
    builder.addSymlinksToArtifacts(Iterables.filter(fakeLinkerInputs,Artifact.MIDDLEMAN_FILTER));
    builder.addTransitiveArtifacts(toolchain.getCrosstool());
    builder.addTransitiveArtifacts(toolchain.getLibcLink());
    ImmutableSet.Builder<Artifact> sourcesBuilder=ImmutableSet.<Artifact>builder();
    for (    CppSource cppSource : cAndCppSources) {
      sourcesBuilder.add(cppSource.getSource());
    }
    builder.addSymlinksToArtifacts(sourcesBuilder.build());
    CppCompilationContext cppCompilationContext=info.getCppCompilationContext();
    builder.addSymlinksToArtifacts(cppCompilationContext.getDeclaredIncludeSrcs());
    builder.addSymlinksToArtifacts(cppCompilationContext.getAdditionalInputs());
    builder.addSymlinksToArtifacts(cppCompilationContext.getTransitiveModules(CppHelper.usePic(context,!isLinkShared(context))));
  }
  return builder.build();
}