[cfe-commits] r145018 - in /cfe/trunk: include/clang/Driver/Compilation.h lib/Driver/Driver.cpp lib/Driver/Tools.cpp test/Driver/crash-cleanup.c test/Driver/output-file-cleanup.c

Peter Collingbourne peter at pcc.me.uk
Sun Nov 20 16:01:05 PST 2011


Author: pcc
Date: Sun Nov 20 18:01:05 2011
New Revision: 145018

URL: http://llvm.org/viewvc/llvm-project?rev=145018&view=rev
Log:
Teach the driver about failure result files, which are compilation
output files that are valid regardless of whether the compilation
succeeded or failed (but not if we crash).  Add depfiles to the
failure result file list.

Added:
    cfe/trunk/test/Driver/output-file-cleanup.c
Removed:
    cfe/trunk/test/Driver/crash-cleanup.c
Modified:
    cfe/trunk/include/clang/Driver/Compilation.h
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/include/clang/Driver/Compilation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Compilation.h?rev=145018&r1=145017&r2=145018&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Compilation.h (original)
+++ cfe/trunk/include/clang/Driver/Compilation.h Sun Nov 20 18:01:05 2011
@@ -56,6 +56,10 @@
   /// Result files which should be removed on failure.
   ArgStringList ResultFiles;
 
+  /// Result files which are generated correctly on failure, and which should
+  /// only be removed if we crash.
+  ArgStringList FailureResultFiles;
+
   /// Redirection for stdout, stderr, etc.
   const llvm::sys::Path **Redirects;
 
@@ -84,6 +88,10 @@
 
   const ArgStringList &getResultFiles() const { return ResultFiles; }
 
+  const ArgStringList &getFailureResultFiles() const {
+    return FailureResultFiles;
+  }
+
   /// getArgsForToolChain - Return the derived argument list for the
   /// tool chain \arg TC (or the default tool chain, if TC is not
   /// specified).
@@ -106,6 +114,13 @@
     return Name;
   }
 
+  /// addFailureResultFile - Add a file to remove if we crash, and returns its
+  /// argument.
+  const char *addFailureResultFile(const char *Name) {
+    FailureResultFiles.push_back(Name);
+    return Name;
+  }
+
   /// CleanupFileList - Remove the files in the given list.
   ///
   /// \param IssueErrors - Report failures as errors.

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=145018&r1=145017&r2=145018&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Sun Nov 20 18:01:05 2011
@@ -507,9 +507,14 @@
     return Res;
 
   // Otherwise, remove result files as well.
-  if (!C.getArgs().hasArg(options::OPT_save_temps))
+  if (!C.getArgs().hasArg(options::OPT_save_temps)) {
     C.CleanupFileList(C.getResultFiles(), true);
 
+    // Failure result files are valid unless we crashed.
+    if (Res < 0)
+      C.CleanupFileList(C.getFailureResultFiles(), true);
+  }
+
   // Print extra information about abnormal failures, if possible.
   //
   // This is ad-hoc, but we don't want to be excessively noisy. If the result

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=145018&r1=145017&r2=145018&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Sun Nov 20 18:01:05 2011
@@ -218,11 +218,13 @@
       DepFile = Output.getFilename();
     } else if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
       DepFile = MF->getValue(Args);
+      C.addFailureResultFile(DepFile);
     } else if (A->getOption().matches(options::OPT_M) ||
                A->getOption().matches(options::OPT_MM)) {
       DepFile = "-";
     } else {
       DepFile = darwin::CC1::getDependencyFileName(Args, Inputs);
+      C.addFailureResultFile(DepFile);
     }
     CmdArgs.push_back("-dependency-file");
     CmdArgs.push_back(DepFile);

Removed: cfe/trunk/test/Driver/crash-cleanup.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/crash-cleanup.c?rev=145017&view=auto
==============================================================================
--- cfe/trunk/test/Driver/crash-cleanup.c (original)
+++ cfe/trunk/test/Driver/crash-cleanup.c (removed)
@@ -1,9 +0,0 @@
-// RUN: not %clang -o %t.o -MMD -MF %t.d %s
-// RUN: test ! -f %t.o
-// RUN: test ! -f %t.d
-// REQUIRES: shell
-// REQUIRES: crash-recovery
-
-// XFAIL: *
-
-#pragma clang __debug crash

Added: cfe/trunk/test/Driver/output-file-cleanup.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/output-file-cleanup.c?rev=145018&view=auto
==============================================================================
--- cfe/trunk/test/Driver/output-file-cleanup.c (added)
+++ cfe/trunk/test/Driver/output-file-cleanup.c Sun Nov 20 18:01:05 2011
@@ -0,0 +1,20 @@
+// RUN: touch %t.o
+// RUN: not %clang -DCRASH -o %t.o -MMD -MF %t.d %s
+// RUN: test ! -f %t.o
+// RUN: test ! -f %t.d
+
+// RUN: touch %t.o
+// RUN: not %clang -o %t.o -MMD -MF %t.d %s
+// RUN: test ! -f %t.o
+// RUN: test -f %t.d
+
+// REQUIRES: shell
+// REQUIRES: crash-recovery
+
+// XFAIL: darwin
+
+#ifdef CRASH
+#pragma clang __debug crash
+#else
+invalid C code
+#endif





More information about the cfe-commits mailing list