[Clang][Driver] Remove -M group options before generating crash diagnostics
authorAlexandre Ganea <alexandre.ganea@ubisoft.com>
Thu, 6 Feb 2020 21:23:25 +0000 (16:23 -0500)
committerAlexandre Ganea <alexandre.ganea@ubisoft.com>
Thu, 6 Feb 2020 21:23:25 +0000 (16:23 -0500)
Previously, when using '-MF file.d' on the command line, 'file.d' would not be deleted after a compiler crash.

The code path in Compilation::initCompilationForDiagnostics()  that was modifying 'TranslatedArgs' had no effect, because 'TCArgs' was already created after the crash.

This was covered by clang/test/Driver/output-file-cleanup.c, the test was succeeding by fluke because Driver::generateCompilationDiagnostics() would fail to launch the subsequent clang -E (see D74070 for a fix for this). So the test was only covering Driver.cpp, C.CleanupFileMap().
After this patch, both cleanup and removal of -MF are exercised.

Differential Revision: https://reviews.llvm.org/D74076

clang/lib/Driver/Compilation.cpp
clang/test/Driver/output-file-cleanup.c

index 25aec36..5247757 100644 (file)
@@ -258,14 +258,23 @@ void Compilation::initCompilationForDiagnostics() {
 
   // Remove any user specified output.  Claim any unclaimed arguments, so as
   // to avoid emitting warnings about unused args.
-  OptSpecifier OutputOpts[] = { options::OPT_o, options::OPT_MD,
-                                options::OPT_MMD };
+  OptSpecifier OutputOpts[] = {
+      options::OPT_o,  options::OPT_MD, options::OPT_MMD, options::OPT_M,
+      options::OPT_MM, options::OPT_MF, options::OPT_MG,  options::OPT_MJ,
+      options::OPT_MQ, options::OPT_MT, options::OPT_MV};
   for (unsigned i = 0, e = llvm::array_lengthof(OutputOpts); i != e; ++i) {
     if (TranslatedArgs->hasArg(OutputOpts[i]))
       TranslatedArgs->eraseArg(OutputOpts[i]);
   }
   TranslatedArgs->ClaimAllArgs();
 
+  // Force re-creation of the toolchain Args, otherwise our modifications just
+  // above will have no effect.
+  for (auto Arg : TCArgs)
+    if (Arg.second != TranslatedArgs)
+      delete Arg.second;
+  TCArgs.clear();
+
   // Redirect stdout/stderr to /dev/null.
   Redirects = {None, {""}, {""}};
 
index 4dcb5ae..c572b25 100644 (file)
@@ -1,7 +1,4 @@
 
-// Temporarily disable this test until the -MF flag is properly removed from the diagnostics generation.
-// XFAIL: *
-
 // RUN: rm -f "%t.d" "%t1.s" "%t2.s" "%t3.s" "%t4.s" "%t5.s"
 //
 // RUN: touch %t.s