r344375 - [Driver] check for exit code from SIGPIPE

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 12 11:10:51 PDT 2018


This patch makes a lot of posix assumptions, and that header file doesn't
exist on Windows. I reverted this to fix the build, but you might want to
reconsider how this is designed.

On Fri, Oct 12, 2018 at 10:24 AM Nick Desaulniers via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: nickdesaulniers
> Date: Fri Oct 12 10:22:46 2018
> New Revision: 344375
>
> URL: http://llvm.org/viewvc/llvm-project?rev=344375&view=rev
> Log:
> [Driver] check for exit code from SIGPIPE
>
> Summary:
> D53000 adds a special exit code for SIGPIPE (writing to a closed
> reader), and rather than print a fatal warning, skips printing the
> error.  This can be seen commonly from piping into head, tee, or
> split.
>
> Fixes PR25349, rdar://problem/14285346, b/77310947
> <https://buganizer.corp.google.com/77310947>.
>
> Reviewers: jfb
>
> Reviewed By: jfb
>
> Subscribers: cfe-commits, thakis, srhines
>
> Differential Revision: https://reviews.llvm.org/D53001
>
> Modified:
>     cfe/trunk/lib/Driver/Driver.cpp
>
> Modified: cfe/trunk/lib/Driver/Driver.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=344375&r1=344374&r2=344375&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Driver/Driver.cpp (original)
> +++ cfe/trunk/lib/Driver/Driver.cpp Fri Oct 12 10:22:46 2018
> @@ -78,6 +78,7 @@
>  #include "llvm/Support/raw_ostream.h"
>  #include <map>
>  #include <memory>
> +#include <sysexits.h>
>  #include <utility>
>  #if LLVM_ON_UNIX
>  #include <unistd.h> // getpid
> @@ -1388,8 +1389,9 @@ int Driver::ExecuteCompilation(
>
>    // Otherwise, remove result files and print extra information about
> abnormal
>    // failures.
> +  int Res = 0;
>    for (const auto &CmdPair : FailingCommands) {
> -    int Res = CmdPair.first;
> +    int CommandRes = CmdPair.first;
>      const Command *FailingCommand = CmdPair.second;
>
>      // Remove result files if we're not saving temps.
> @@ -1398,10 +1400,17 @@ int Driver::ExecuteCompilation(
>        C.CleanupFileMap(C.getResultFiles(), JA, true);
>
>        // Failure result files are valid unless we crashed.
> -      if (Res < 0)
> +      if (CommandRes < 0)
>          C.CleanupFileMap(C.getFailureResultFiles(), JA, true);
>      }
>
> +    // llvm/lib/Support/Unix/Signals.inc will exit with a special return
> code
> +    // for SIGPIPE. Do not print diagnostics for this case.
> +    if (CommandRes == EX_IOERR) {
> +      Res = CommandRes;
> +      continue;
> +    }
> +
>      // Print extra information about abnormal failures, if possible.
>      //
>      // This is ad-hoc, but we don't want to be excessively noisy. If the
> result
> @@ -1411,17 +1420,17 @@ int Driver::ExecuteCompilation(
>      // diagnostics, so always print the diagnostic there.
>      const Tool &FailingTool = FailingCommand->getCreator();
>
> -    if (!FailingCommand->getCreator().hasGoodDiagnostics() || Res != 1) {
> +    if (!FailingCommand->getCreator().hasGoodDiagnostics() || CommandRes
> != 1) {
>        // FIXME: See FIXME above regarding result code interpretation.
> -      if (Res < 0)
> +      if (CommandRes < 0)
>          Diag(clang::diag::err_drv_command_signalled)
>              << FailingTool.getShortName();
>        else
> -        Diag(clang::diag::err_drv_command_failed) <<
> FailingTool.getShortName()
> -                                                  << Res;
> +        Diag(clang::diag::err_drv_command_failed)
> +            << FailingTool.getShortName() << CommandRes;
>      }
>    }
> -  return 0;
> +  return Res;
>  }
>
>  void Driver::PrintHelp(bool ShowHidden) const {
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181012/abd09ea9/attachment.html>


More information about the cfe-commits mailing list