]> granicus.if.org Git - clang/commitdiff
Add the depfile as a result file so that it is deleted if we crash,
authorPeter Collingbourne <peter@pcc.me.uk>
Sun, 6 Nov 2011 00:40:05 +0000 (00:40 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Sun, 6 Nov 2011 00:40:05 +0000 (00:40 +0000)
and prevent the diagnostic preprocessor run from writing a depfile.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143846 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Compilation.cpp
lib/Driver/Tools.cpp
lib/Driver/Tools.h
test/Driver/crash-cleanup.c [new file with mode: 0644]

index d02da9588a639a1f5601e2c03f2df0f108441c60..42c84493fa6aca48d3d2b601c694560c35621d8b 100644 (file)
@@ -217,8 +217,12 @@ void Compilation::initCompilationForDiagnostics(void) {
 
   // Remove any user specified output.  Claim any unclaimed arguments, so as
   // to avoid emitting warnings about unused args.
-  if (TranslatedArgs->hasArg(options::OPT_o))
-    TranslatedArgs->eraseArg(options::OPT_o);
+  OptSpecifier OutputOpts[] = { options::OPT_o, options::OPT_MD,
+                                options::OPT_MMD };
+  for (unsigned i = 0; i != sizeof(OutputOpts)/sizeof(OutputOpts[0]); ++i) {
+    if (TranslatedArgs->hasArg(OutputOpts[i]))
+      TranslatedArgs->eraseArg(OutputOpts[i]);
+  }
   TranslatedArgs->ClaimAllArgs();
 
   // Redirect stdout/stderr to /dev/null.
index c4e536079e19d034b031e13d6394014543688ebe..7d46793a5f38e121c26a094a9742a5e7b35c3fdf 100644 (file)
@@ -203,7 +203,8 @@ static void AddIncludeDirectoryList(const ArgList &Args,
   }
 }
 
-void Clang::AddPreprocessingOptions(const Driver &D,
+void Clang::AddPreprocessingOptions(Compilation &C,
+                                    const Driver &D,
                                     const ArgList &Args,
                                     ArgStringList &CmdArgs,
                                     const InputInfo &Output,
@@ -225,11 +226,13 @@ void Clang::AddPreprocessingOptions(const Driver &D,
       DepFile = Output.getFilename();
     } else if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
       DepFile = MF->getValue(Args);
+      C.addResultFile(DepFile);
     } else if (A->getOption().matches(options::OPT_M) ||
                A->getOption().matches(options::OPT_MM)) {
       DepFile = "-";
     } else {
       DepFile = darwin::CC1::getDependencyFileName(Args, Inputs);
+      C.addResultFile(DepFile);
     }
     CmdArgs.push_back("-dependency-file");
     CmdArgs.push_back(DepFile);
@@ -1541,7 +1544,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   //
   // FIXME: Support -fpreprocessed
   if (types::getPreprocessedType(InputType) != types::TY_INVALID)
-    AddPreprocessingOptions(D, Args, CmdArgs, Output, Inputs);
+    AddPreprocessingOptions(C, D, Args, CmdArgs, Output, Inputs);
 
   // Don't warn about "clang -c -DPIC -fPIC test.i" because libtool.m4 assumes
   // that "The compiler can only warn and ignore the option if not recognized".
index a4f732e1c213ff122015ac40c2b136dd91e70ffc..d81c987cf04bacd4bc8ca6cd860e1b7a94505bd4 100644 (file)
@@ -29,7 +29,8 @@ namespace tools {
 
   /// \brief Clang compiler tool.
   class LLVM_LIBRARY_VISIBILITY Clang : public Tool {
-    void AddPreprocessingOptions(const Driver &D,
+    void AddPreprocessingOptions(Compilation &C,
+                                 const Driver &D,
                                  const ArgList &Args,
                                  ArgStringList &CmdArgs,
                                  const InputInfo &Output,
diff --git a/test/Driver/crash-cleanup.c b/test/Driver/crash-cleanup.c
new file mode 100644 (file)
index 0000000..d6d9ae0
--- /dev/null
@@ -0,0 +1,7 @@
+// 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
+
+#pragma clang __debug crash